Skip to content

Commit

Permalink
Ignore errors on TCP send to avoid race with incoming disconnect message
Browse files Browse the repository at this point in the history
THis commit avoids a race condition between an incoming disconnect
message and an attempt to send a new outgoing message. In some cases
the prior implementation would process the TCP close before finishing
processing of messages in the TCP receive buffer, reporting a
BrokenPipeError insted of a clean disconnect.
  • Loading branch information
ronf committed Nov 18, 2023
1 parent e9e95ae commit e7ba87c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions asyncssh/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,10 +1413,10 @@ def _send(self, data: bytes) -> None:
"""Send data to the SSH connection"""

if self._transport:
if self._transport.is_closing():
self._force_close(BrokenPipeError())
else:
try:
self._transport.write(data)
except BrokenPipeError:
pass

def _send_version(self) -> None:
"""Start the SSH handshake"""
Expand Down

0 comments on commit e7ba87c

Please sign in to comment.