From bb89aaa6bcc155b46b6df315fe9ce8c7a9f32eb2 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 13 Mar 2026 16:55:17 +0100 Subject: [PATCH] fix: drop stalled browser websocket clients --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 4432696d..6d718c90 100644 --- a/main.py +++ b/main.py @@ -2005,11 +2005,16 @@ async def _broadcast_to_browser_clients(snapshot: dict): for ws in list(browser_conns): try: - await ws.send_json(data) + await asyncio.wait_for(ws.send_json(data), timeout=1.0) except (WebSocketDisconnect, RuntimeError, ConnectionAbortedError) as e: # Collect disconnected clients for cleanup disconnected_clients.append(ws) 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: # Handle any other unexpected errors disconnected_clients.append(ws)