quart icon indicating copy to clipboard operation
quart copied to clipboard

after_this_websocket is not called if the client disconnects?

Open willstott101 opened this issue 1 year ago • 2 comments

I'm trying to use after_this_websocket to cleanup some long-running tasks that go alongside websocket connections. It appears this isn't called reliably enough for me to use it as a cleanup. My server has a memory leak right now and we think it's due to this.

Environment:

  • Python version: Tox 310 311
  • Quart version: 0.19.5 (current git tip)

I have reproduced this behaviour in the Quart tests: https://github.com/willstott101/quart/pull/1 I hope that's enough info to quickly confirm if this is a bug or accepted behaviour. The docs recommend we always re-raise the cancelled error in websockets which makes it impossible for us to use after_this_websocket for cleanup.

willstott101 avatar May 10 '24 14:05 willstott101

I think this is expected and teardown_websocket is what you are looking for

pgjones avatar Nov 14 '24 10:11 pgjones

There doesn't seem to be a teardown_request. Would it be more intuitive for both after_this_request and after_this_websocket to be usable for cleanup. I don't understand the benefit of teardown_websocket and after_this_websocket being different things.

I can experiment with teardown_websocket - but would a PR which combines teardown_websocket and after_this_websocket be considered?

willstott101 avatar Nov 15 '24 21:11 willstott101