Skip to content

Commit

Permalink
Reduce latancy to set up websocket forwarding in hassio
Browse files Browse the repository at this point in the history
Create the tasks eagerly to avoid one iteration of the event loop
to connect the proxy
  • Loading branch information
bdraco committed Feb 26, 2024
1 parent 359bd62 commit 90cd4ab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions homeassistant/components/hassio/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.typing import UNDEFINED
from homeassistant.util.async_ import create_eager_task

from .const import X_HASS_SOURCE, X_INGRESS_PATH
from .http import should_compress
Expand Down Expand Up @@ -143,8 +144,8 @@ async def _handle_websocket(
# Proxy requests
await asyncio.wait(
[
asyncio.create_task(_websocket_forward(ws_server, ws_client)),
asyncio.create_task(_websocket_forward(ws_client, ws_server)),
create_eager_task(_websocket_forward(ws_server, ws_client)),
create_eager_task(_websocket_forward(ws_client, ws_server)),
],
return_when=asyncio.FIRST_COMPLETED,
)
Expand Down

0 comments on commit 90cd4ab

Please sign in to comment.