Skip to content

Commit 8b84da7

Browse files
dkropachevclaude
andcommitted
Fix handle_write peer-disconnect detection on Windows
On Windows, ProactorEventLoop may raise plain OSError with winerror=10054 (WSAECONNRESET) or 10053 (WSAECONNABORTED) instead of ConnectionResetError. Use ConnectionError base class plus winerror check for robust cross-platform detection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 49ee6d4 commit 8b84da7

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

cassandra/io/asyncioreactor.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,14 @@ async def handle_write(self):
226226
if next_msg:
227227
await self._loop.sock_sendall(self._socket, next_msg)
228228
except socket.error as err:
229-
# Peer disconnected — do a clean close instead of defunct
230-
if isinstance(err, (BrokenPipeError, ConnectionResetError)):
229+
# Peer disconnected — do a clean close instead of defunct.
230+
# Use ConnectionError (parent of BrokenPipeError,
231+
# ConnectionResetError, ConnectionAbortedError) plus a
232+
# winerror check for Windows IOCP which may raise plain
233+
# OSError with winerror=10054 (WSAECONNRESET) or
234+
# 10053 (WSAECONNABORTED).
235+
if (isinstance(err, ConnectionError)
236+
or getattr(err, 'winerror', None) in (10053, 10054)):
231237
log.debug("Connection %s closed by peer during write: %s",
232238
self, err)
233239
self.close()

0 commit comments

Comments
 (0)