Reduce number of aiohttp.TCPConnector cleanup_closed checks to one per minute (#123268)

pull/123407/head
J. Nick Koston 2024-08-08 15:52:09 -05:00 committed by GitHub
parent 2343f5e40f
commit 69740e865c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -285,6 +285,21 @@ def _make_key(
return (verify_ssl, family)
class HomeAssistantTCPConnector(aiohttp.TCPConnector):
"""Home Assistant TCP Connector.
Same as aiohttp.TCPConnector but with a longer cleanup_closed timeout.
By default the cleanup_closed timeout is 2 seconds. This is too short
for Home Assistant since we churn through a lot of connections. We set
it to 60 seconds to reduce the overhead of aborting TLS connections
that are likely already closed.
"""
# abort transport after 60 seconds (cleanup broken connections)
_cleanup_closed_period = 60.0
@callback
def _async_get_connector(
hass: HomeAssistant,
@ -306,7 +321,7 @@ def _async_get_connector(
else:
ssl_context = ssl_util.get_default_no_verify_context()
connector = aiohttp.TCPConnector(
connector = HomeAssistantTCPConnector(
family=family,
enable_cleanup_closed=ENABLE_CLEANUP_CLOSED,
ssl=ssl_context,