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 race conditions in AsyncioConnection that cause "[Errno 9] Bad
file descriptor" errors during node restarts, especially with TLS:
1. close() now waits for _close() to complete when called from outside
the event loop thread, eliminating the window where is_closed=True
but the socket fd is still open.
2. handle_read() sets last_error on server EOF so factory() detects dead
connections instead of returning them to callers.
3. handle_write() treats peer disconnections as clean close instead of
defuncting, and both I/O handlers skip defunct() if the connection
is already shutting down.
Peer-disconnect detection is extracted into _is_peer_disconnect() helper
covering platform-specific behaviors:
- Windows: ProactorEventLoop raises plain OSError with winerror 10054
(WSAECONNRESET) or 10053 (WSAECONNABORTED) instead of
ConnectionResetError. Detection uses ConnectionError base class plus
winerror check.
- macOS: Raises OSError(57) ENOTCONN when writing to a
peer-disconnected socket, which is not a ConnectionError subclass.
Detection uses errno-based checks for ENOTCONN, ESHUTDOWN,
ECONNRESET, and ECONNABORTED.
- Windows _close(): ProactorEventLoop does not support
remove_reader/remove_writer (raises NotImplementedError). These calls
are wrapped so the socket is always closed regardless, and try/finally
ensures connected_event is always set even if cleanup fails.
0 commit comments