From 3c30418d48618a58b00618881208c673bca58be8 Mon Sep 17 00:00:00 2001 From: John Belmonte Date: Mon, 1 Feb 2021 22:41:27 +0900 Subject: [PATCH] server: close TCP connection after closing websocket Fixes #115 and #147. --- trio_websocket/_impl.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/trio_websocket/_impl.py b/trio_websocket/_impl.py index 36d6cbf..693c379 100644 --- a/trio_websocket/_impl.py +++ b/trio_websocket/_impl.py @@ -1094,6 +1094,12 @@ async def _handle_close_connection_event(self, event): await self._send(event.response()) await self._close_web_socket(event.code, event.reason or None) self._close_handshake.set() + # RFC: "When a server is instructed to Close the WebSocket Connection + # it SHOULD initiate a TCP Close immediately, and when a client is + # instructed to do the same, it SHOULD wait for a TCP Close from the + # server." + if self.is_server: + await self._close_stream() async def _handle_message_event(self, event): '''