Skip to content

Commit

Permalink
Fix unclosed transport warning (#8875)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0478f14)
  • Loading branch information
Dreamsorcerer authored and patchback[bot] committed Aug 26, 2024
1 parent 770fdcb commit c6af496
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGES/8875.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed an unclosed transport ``ResourceWarning`` on web handlers -- by :user:`Dreamsorcerer`.
15 changes: 3 additions & 12 deletions aiohttp/web_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,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):
Expand All @@ -281,9 +278,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)
Expand All @@ -307,13 +302,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
Expand All @@ -326,9 +320,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()

Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,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 <asyncio.sslproto._SSLProtocolTransport object.*:ResourceWarning
ignore:unclosed transport <_ProactorSocketTransport closing fd=-1>:ResourceWarning
ignore:Unclosed client session <aiohttp.client.ClientSession object at 0x:ResourceWarning
# Temporarily ignore warnings internal to Python 3.9.7, can be removed again in 3.9.8.
ignore:The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.:DeprecationWarning:asyncio
Expand Down

0 comments on commit c6af496

Please sign in to comment.