From e7ba87cd96b65c77d860c5dd59a2363864f48561 Mon Sep 17 00:00:00 2001 From: Ron Frederick Date: Fri, 17 Nov 2023 18:02:22 -0800 Subject: [PATCH] Ignore errors on TCP send to avoid race with incoming disconnect message 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. --- asyncssh/connection.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/asyncssh/connection.py b/asyncssh/connection.py index bd30c82..4cf9517 100644 --- a/asyncssh/connection.py +++ b/asyncssh/connection.py @@ -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"""