You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(websocket): Raise IOException on closed connection instead of returning b"" (#1213)
* fix(websocket): Raise IOException on closed connection instead of returning b""
Fixes#1212
- WebSocket read() now raises IOException when connection is closed,
allowing read_exactly() to immediately detect closure instead of
retrying 100 times on empty bytes
- Yamux send_window_update() gracefully handles connection closure
errors during window updates (data was already read successfully)
- Improved _extract_close_info() fallback for non-standard exceptions
- Added exception chaining (from e) in write() for better tracebacks
- Comprehensive test suite for closure handling scenarios
Co-authored-by: Cursor <cursoragent@cursor.com>
* refactor(exceptions): Replace fragile string matching with typed ConnectionClosedError
Add ConnectionClosedError(IOException) with structured close_code,
close_reason, and transport attributes. The WebSocket transport now
raises this typed exception instead of a plain IOException with the
close info buried in the message string. Yamux catches it by type
(`except ConnectionClosedError`) instead of parsing `str(e).lower()`
for closure keywords — eliminating a fragile pattern that would
silently break if anyone changed an error message.
A string-matching fallback is retained for transports that don't yet
raise ConnectionClosedError (e.g. TCP RawConnError).
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Fixed WebSocket transport to immediately raise ``IOException`` on connection closure instead of returning empty bytes, preventing retry loops in ``read_exactly()``. Also added graceful error handling in yamux ``send_window_update()`` for connections closed by peers during window updates.
0 commit comments