Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/9726.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Passing ``enable_cleanup_closed`` to :py:class:`aiohttp.TCPConnector` is now ignored on Python 3.12.7+ and 3.13.1+ since the underlying bug that caused asyncio to leak SSL connections has been fixed upstream -- by :user:`bdraco`.
19 changes: 19 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
HTTP_AND_EMPTY_SCHEMA_SET = HTTP_SCHEMA_SET | EMPTY_SCHEMA_SET
HIGH_LEVEL_SCHEMA_SET = HTTP_AND_EMPTY_SCHEMA_SET | WS_SCHEMA_SET

NEEDS_CLEANUP_CLOSED = (3, 13, 0) <= sys.version_info < (
3,
13,
1,
) or sys.version_info < (3, 12, 7)
# Cleanup closed is no longer needed after https://github.com/python/cpython/pull/118960
# which first appeared in Python 3.12.7 and 3.13.1


__all__ = ("BaseConnector", "TCPConnector", "UnixConnector", "NamedPipeConnector")

Expand Down Expand Up @@ -270,6 +278,17 @@ def __init__(

# start cleanup closed transports task
self._cleanup_closed_handle: Optional[asyncio.TimerHandle] = None

if enable_cleanup_closed and not NEEDS_CLEANUP_CLOSED:
warnings.warn(
"enable_cleanup_closed ignored because "
"https://github.com/python/cpython/pull/118960 is fixed in "
"this Python version {sys.version_info}.",
DeprecationWarning,
stacklevel=2,
)
enable_cleanup_closed = False

self._cleanup_closed_disabled = not enable_cleanup_closed
self._cleanup_closed_transports: List[Optional[asyncio.Transport]] = []

Expand Down
6 changes: 5 additions & 1 deletion docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -963,10 +963,14 @@ is controlled by *force_close* constructor's parameter).
connection releasing (optional).

:param bool enable_cleanup_closed: some SSL servers do not properly complete
SSL shutdown process, in that case asyncio leaks ssl connections.
SSL shutdown process, in that case asyncio leaks SSL connections.
If this parameter is set to True, aiohttp additionally aborts underlining
transport after 2 seconds. It is off by default.

For Python version 3.12.7+, or 3.13.1 and later,
this parameter is ignored because the asyncio SSL connection
leak is fixed in Python.


:param loop: :ref:`event loop<asyncio-event-loop>`
used for handling connections.
Expand Down
Loading