Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid shutdown on closed socket. #1086

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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