Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unclosed transport warning #8875

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Dreamsorcerer marked this conversation as resolved.
Show resolved Hide resolved
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)
bdraco marked this conversation as resolved.
Show resolved Hide resolved

# 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
Loading