Skip to content

Commit 30db72d

Browse files
authored
Add WebSocket proxy timeout handling (#6138)
Add TimeoutError handling for WebSocket connections to add-ons. Also log debug information for WebSocket proxy connections.
1 parent 00a78f3 commit 30db72d

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

supervisor/api/ingress.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,25 @@ async def _handle_websocket(
199199
url = f"{url}?{request.query_string}"
200200

201201
# Start proxy
202-
async with self.sys_websession.ws_connect(
203-
url,
204-
headers=source_header,
205-
protocols=req_protocols,
206-
autoclose=False,
207-
autoping=False,
208-
) as ws_client:
209-
# Proxy requests
210-
await asyncio.wait(
211-
[
212-
self.sys_create_task(_websocket_forward(ws_server, ws_client)),
213-
self.sys_create_task(_websocket_forward(ws_client, ws_server)),
214-
],
215-
return_when=asyncio.FIRST_COMPLETED,
216-
)
202+
try:
203+
_LOGGER.debug("Proxing WebSocket to %s, upstream url: %s", addon.slug, url)
204+
async with self.sys_websession.ws_connect(
205+
url,
206+
headers=source_header,
207+
protocols=req_protocols,
208+
autoclose=False,
209+
autoping=False,
210+
) as ws_client:
211+
# Proxy requests
212+
await asyncio.wait(
213+
[
214+
self.sys_create_task(_websocket_forward(ws_server, ws_client)),
215+
self.sys_create_task(_websocket_forward(ws_client, ws_server)),
216+
],
217+
return_when=asyncio.FIRST_COMPLETED,
218+
)
219+
except TimeoutError:
220+
_LOGGER.warning("WebSocket proxy to %s timed out", addon.slug)
217221

218222
return ws_server
219223

0 commit comments

Comments
 (0)