Skip to content

Commit a965cc4

Browse files
dkropachevclaude
andcommitted
Fix macOS ENOTCONN detection in handle_write peer-disconnect check
macOS raises OSError(57, "Socket is not connected") (ENOTCONN) when writing to a peer-disconnected socket. Unlike BrokenPipeError or ConnectionResetError, this is a plain OSError — not a ConnectionError subclass — so it was not caught by the isinstance(err, ConnectionError) check. Add errno-based detection for ENOTCONN, ESHUTDOWN, ECONNRESET, and ECONNABORTED to handle these platform-specific disconnect errors cleanly instead of defuncting the connection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8b84da7 commit a965cc4

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

cassandra/io/asyncioreactor.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import errno
12
import threading
23

34
from cassandra.connection import Connection, ConnectionShutdown
@@ -232,8 +233,15 @@ async def handle_write(self):
232233
# winerror check for Windows IOCP which may raise plain
233234
# OSError with winerror=10054 (WSAECONNRESET) or
234235
# 10053 (WSAECONNABORTED).
236+
# Also check errno for ENOTCONN/ESHUTDOWN/ECONNRESET
237+
# which macOS raises as plain OSError (not ConnectionError).
238+
_peer_errnos = (
239+
errno.ENOTCONN, errno.ESHUTDOWN,
240+
errno.ECONNRESET, errno.ECONNABORTED,
241+
)
235242
if (isinstance(err, ConnectionError)
236-
or getattr(err, 'winerror', None) in (10053, 10054)):
243+
or getattr(err, 'winerror', None) in (10053, 10054)
244+
or getattr(err, 'errno', None) in _peer_errnos):
237245
log.debug("Connection %s closed by peer during write: %s",
238246
self, err)
239247
self.close()

0 commit comments

Comments
 (0)