-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Problem
When using the WebSocket the server sometimes crashes with RuntimeError: ASGI flow error
Traceback points to await client.receive() in ws_endpoint backend/server/websocket.py:57
This usually happens if the client disconnects (or the connection is otherwise closed) while the server is still awaiting receive(). Instead of being handled gracefully, the exception bubbles up and kills the request handler.
Expected behavior
Disconnected clients should raise a clean WebSocketDisconnect (or similar handled exception), not an unhandled RuntimeError.
Server should log the disconnect and exit the loop gracefully without stack traces.
Proposed solution
Wrap WebSocket receive loop in try/except for WebSocketDisconnect and RuntimeError.
Alternatively, update client.receive() wrapper (backend/server/websocket.py:57) to catch RuntimeError and re-raise a WebSocketDisconnect so calling code doesn’t need to know about Starlette internals.
