Skip to content

Commit

Permalink
Avoid shutdown on closed socket.
Browse files Browse the repository at this point in the history
  • Loading branch information
aaugustin committed Nov 14, 2021
1 parent ce611d7 commit 448e777
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/websockets/legacy/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ async def close_connection(self) -> None:
self.logger.debug("! timed out waiting for TCP close")

# Half-close the TCP connection if possible (when there's no TLS).
if self.transport.can_write_eof():
if self.transport.can_write_eof() and not self.transport.is_closing():
if self.debug:
self.logger.debug("x half-closing TCP connection")
self.transport.write_eof()
Expand Down
3 changes: 3 additions & 0 deletions tests/legacy/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def setup_mock(self, loop, protocol):
def can_write_eof(self):
return True

def is_closing(self):
return False

def write_eof(self):
# When the protocol half-closes the TCP connection, it expects the
# other end to close it. Simulate that.
Expand Down

0 comments on commit 448e777

Please sign in to comment.