Skip to content

Commit

Permalink
Fix unclosed transport warning (#8875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer authored Aug 26, 2024
1 parent 6d97427 commit 0478f14
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 @@ -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):
Expand All @@ -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)
Expand All @@ -330,13 +325,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 @@ -349,9 +343,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 @@ -136,8 +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 <asyncio.sslproto._SSLProtocolTransport object.*:ResourceWarning
ignore:unclosed transport <_ProactorSocketTransport closing fd=-1>:ResourceWarning
ignore:Unclosed client session <aiohttp.client.ClientSession object at 0x:ResourceWarning
ignore:The loop argument is deprecated:DeprecationWarning:asyncio
ignore:Creating a LegacyVersion has been deprecated and will be removed in the next major release:DeprecationWarning::
Expand Down

0 comments on commit 0478f14

Please sign in to comment.