Skip to content

Commit 448e777

Browse files
committed
Avoid shutdown on closed socket.
Fix #1072.
1 parent ce611d7 commit 448e777

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/websockets/legacy/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ async def close_connection(self) -> None:
13031303
self.logger.debug("! timed out waiting for TCP close")
13041304

13051305
# Half-close the TCP connection if possible (when there's no TLS).
1306-
if self.transport.can_write_eof():
1306+
if self.transport.can_write_eof() and not self.transport.is_closing():
13071307
if self.debug:
13081308
self.logger.debug("x half-closing TCP connection")
13091309
self.transport.write_eof()

tests/legacy/test_protocol.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def setup_mock(self, loop, protocol):
5959
def can_write_eof(self):
6060
return True
6161

62+
def is_closing(self):
63+
return False
64+
6265
def write_eof(self):
6366
# When the protocol half-closes the TCP connection, it expects the
6467
# other end to close it. Simulate that.

0 commit comments

Comments
 (0)