From dd4c3b4926b01e5b35bc0a483ba338cf9a7194d7 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 17 Dec 2023 11:42:17 -1000 Subject: [PATCH] never let it leak --- aiohttp/web_ws.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/aiohttp/web_ws.py b/aiohttp/web_ws.py index 215afc26ecb..aac2610c07a 100644 --- a/aiohttp/web_ws.py +++ b/aiohttp/web_ws.py @@ -496,12 +496,15 @@ async def receive(self, timeout: Optional[float] = None) -> WSMessage: self._closing = True self._close_code = msg.data # Could be closed while awaiting reader. - if not self._closed and self._autoclose: # type: ignore[redundant-expr] + if not self._closed: # The client is going to close the connection # out from under us so we do not want to drain # any pending writes as it will likely result # writing to a broken pipe. - await self.close(drain=False) + if self._autoclose: + await self.close(drain=False) + else: + self._set_code_close_transport(msg.data) elif msg.type == WSMsgType.CLOSING: self._closing = True elif msg.type == WSMsgType.PING and self._autoping: