fix: drop stalled browser websocket clients
This commit is contained in:
parent
a3c3d0286e
commit
bb89aaa6bc
1 changed files with 6 additions and 1 deletions
7
main.py
7
main.py
|
|
@ -2005,11 +2005,16 @@ async def _broadcast_to_browser_clients(snapshot: dict):
|
||||||
|
|
||||||
for ws in list(browser_conns):
|
for ws in list(browser_conns):
|
||||||
try:
|
try:
|
||||||
await ws.send_json(data)
|
await asyncio.wait_for(ws.send_json(data), timeout=1.0)
|
||||||
except (WebSocketDisconnect, RuntimeError, ConnectionAbortedError) as e:
|
except (WebSocketDisconnect, RuntimeError, ConnectionAbortedError) as e:
|
||||||
# Collect disconnected clients for cleanup
|
# Collect disconnected clients for cleanup
|
||||||
disconnected_clients.append(ws)
|
disconnected_clients.append(ws)
|
||||||
logger.debug(f"Detected disconnected browser client: {e}")
|
logger.debug(f"Detected disconnected browser client: {e}")
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
disconnected_clients.append(ws)
|
||||||
|
logger.warning(
|
||||||
|
"Timed out broadcasting to browser client; removing stale connection"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Handle any other unexpected errors
|
# Handle any other unexpected errors
|
||||||
disconnected_clients.append(ws)
|
disconnected_clients.append(ws)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue