Commit a21b714
fix: catch ClosedResourceError in error handler to prevent crash on client disconnect
When a client disconnects during request processing, _handle_message
receives the exception and tries to send a log message back to the
client via send_log_message(). Since the write stream is already closed,
this raises ClosedResourceError (or BrokenResourceError), which is
unhandled and crashes the stateless session with an ExceptionGroup.
Wrap the send_log_message() call in a try/except that catches both
anyio.ClosedResourceError and anyio.BrokenResourceError, since failing
to notify a disconnected client is expected and harmless.
This is a different code path from PR #1384, which fixed the message
router loop. This fix covers the _handle_post_request → _handle_message
→ send_log_message error recovery path.
Fixes #2064
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 62575ed commit a21b714
1 file changed
+10
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
425 | 430 | | |
426 | 431 | | |
427 | 432 | | |
| |||
0 commit comments