Skip to content

Commit

Permalink
Reduce number of aiohttp.TCPConnector cleanup_closed checks to one pe…
Browse files Browse the repository at this point in the history
…r minute (#123268)
  • Loading branch information
bdraco authored Aug 8, 2024
1 parent 2343f5e commit 69740e8
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion homeassistant/helpers/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 69740e8

Please sign in to comment.