Enhancement: Graceful cancellation of handler on client disconnect #2496
Replies: 3 comments 10 replies
-
Can you link the fastapi issue please? |
Beta Was this translation helpful? Give feedback.
-
Probably an easy workaround can be built using a litestar/litestar/response/streaming.py Line 83 in 0674fba |
Beta Was this translation helpful? Give feedback.
-
As of Litestar 2.12 at least (didn't investigate for which older version this was not the case), the handlers are cancelled on disconnect. See the tests for proof and clarity: https://github.com/dorinclisu/runner-with-api/blob/main/tests/litestar/test_cancellation.py EDIT: no they aren't, but it can be easily achieved, see bellow. |
Beta Was this translation helpful? Give feedback.
-
Summary
I am unsure if this already possible, but it seems that one can't detect a client disconnection in order to prevent costly db operations. The example is taken from a similar question reported for fastapi.
Basic Example
Drawbacks and Impact
No response
Unresolved questions
No response
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh Litestar dashboard
Beta Was this translation helpful? Give feedback.
All reactions