From 3f480010fd957abca7c98428c353c06c7eba9455 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sat, 24 Aug 2024 16:09:39 +0100 Subject: [PATCH 1/5] Fix unclosed transport warning --- setup.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 20603bf2320..e3fe426a69d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -136,7 +136,6 @@ addopts = filterwarnings = error ignore:module 'ssl' has no attribute 'OP_NO_COMPRESSION'. The Python interpreter is compiled against OpenSSL < 1.0.0. Ref. https.//docs.python.org/3/library/ssl.html#ssl.OP_NO_COMPRESSION:UserWarning - ignore:unclosed transport :ResourceWarning ignore:Unclosed client session Date: Sat, 24 Aug 2024 16:19:24 +0100 Subject: [PATCH 2/5] Update web_protocol.py --- aiohttp/web_protocol.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/aiohttp/web_protocol.py b/aiohttp/web_protocol.py index e0c174e0649..05b1bdbf8af 100644 --- a/aiohttp/web_protocol.py +++ b/aiohttp/web_protocol.py @@ -330,13 +330,12 @@ def connection_lost(self, exc: Optional[BaseException]) -> None: return self._manager.connection_lost(self, exc) - super().connection_lost(exc) - # Grab value before setting _manager to None. handler_cancellation = self._manager.handler_cancellation + self.force_close() + super().connection_lost(exc) self._manager = None - self._force_close = True self._request_factory = None self._request_handler = None self._request_parser = None @@ -349,9 +348,6 @@ def connection_lost(self, exc: Optional[BaseException]) -> None: exc = ConnectionResetError("Connection lost") self._current_request._cancel(exc) - if self._waiter is not None: - self._waiter.cancel() - if handler_cancellation and self._task_handler is not None: self._task_handler.cancel() From 727820e1ea994051d3d5d818ad4c8e2532934284 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sat, 24 Aug 2024 16:25:09 +0100 Subject: [PATCH 3/5] Update setup.cfg --- setup.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index e3fe426a69d..72c03f475c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -136,7 +136,6 @@ addopts = filterwarnings = error ignore:module 'ssl' has no attribute 'OP_NO_COMPRESSION'. The Python interpreter is compiled against OpenSSL < 1.0.0. Ref. https.//docs.python.org/3/library/ssl.html#ssl.OP_NO_COMPRESSION:UserWarning - ignore:unclosed transport <_ProactorSocketTransport closing fd=-1>:ResourceWarning ignore:Unclosed client session Date: Sat, 24 Aug 2024 18:08:56 +0100 Subject: [PATCH 4/5] Create 8875.bugfix.rst --- CHANGES/8875.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/8875.bugfix.rst diff --git a/CHANGES/8875.bugfix.rst b/CHANGES/8875.bugfix.rst new file mode 100644 index 00000000000..fa33df05ae2 --- /dev/null +++ b/CHANGES/8875.bugfix.rst @@ -0,0 +1 @@ +Fixed an unclosed transport ``ResourceWarning`` on web handlers -- by :user:`Dreamsorcerer`. From 3066eda49c8d8d3b6315f07cbb6fb7ca229387b5 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Mon, 26 Aug 2024 16:07:29 +0100 Subject: [PATCH 5/5] Update web_protocol.py --- aiohttp/web_protocol.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/aiohttp/web_protocol.py b/aiohttp/web_protocol.py index 05b1bdbf8af..4ea0706e3ac 100644 --- a/aiohttp/web_protocol.py +++ b/aiohttp/web_protocol.py @@ -283,9 +283,6 @@ async def shutdown(self, timeout: Optional[float] = 15.0) -> None: if self._keepalive_handle is not None: self._keepalive_handle.cancel() - if self._waiter: - self._waiter.cancel() - # Wait for graceful handler completion if self._handler_waiter is not None: with suppress(asyncio.CancelledError, asyncio.TimeoutError): @@ -304,9 +301,7 @@ async def shutdown(self, timeout: Optional[float] = 15.0) -> None: if self._task_handler is not None: self._task_handler.cancel() - if self.transport is not None: - self.transport.close() - self.transport = None + self.force_close() def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport)