Skip to content

Commit 2cf8ade

Browse files
committed
Disable cleanup_closed for aiohttp.TCPConnector with cpython 3.11.2+
There is currently a relatively fast memory leak when using cpython 3.11.2+ and cleanup_closed with aiohttp For my production instance it was leaking ~450MiB per day of `MemoryBIO`, `SSLProtocol`, `SSLObject`, `_SSLProtocolTransport` `memoryview`, and `managedbuffer` objects see aio-libs/aiohttp#7252 see python/cpython#98540
1 parent 051d631 commit 2cf8ade

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

homeassistant/helpers/aiohttp_client.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
APPLICATION_NAME, __version__, aiohttp.__version__, sys.version_info
3838
)
3939

40+
ENABLE_CLEANUP_CLOSED = sys.version_info < (3, 11, 2)
41+
# Enabling cleanup closed on python 3.11.2+ leaks memory relatively quickly
42+
# see https://github.com/aio-libs/aiohttp/issues/7252
43+
# aiohttp interacts poorly with https://github.com/python/cpython/pull/98540
44+
4045
WARN_CLOSE_MSG = "closes the Home Assistant aiohttp session"
4146

4247
#
@@ -276,7 +281,7 @@ def _async_get_connector(
276281
ssl_context = ssl_util.get_default_no_verify_context()
277282

278283
connector = aiohttp.TCPConnector(
279-
enable_cleanup_closed=True,
284+
enable_cleanup_closed=ENABLE_CLEANUP_CLOSED,
280285
ssl=ssl_context,
281286
limit=MAXIMUM_CONNECTIONS,
282287
limit_per_host=MAXIMUM_CONNECTIONS_PER_HOST,

0 commit comments

Comments
 (0)