From 9d196fcfca6171f107053770027a0e83f95a8a67 Mon Sep 17 00:00:00 2001 From: Sases Date: Fri, 19 Jun 2026 13:36:50 +0200 Subject: [PATCH] websocket connection fixes --- als_alert_screen.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/als_alert_screen.html b/als_alert_screen.html index 3d083a2..ed18362 100644 --- a/als_alert_screen.html +++ b/als_alert_screen.html @@ -292,6 +292,13 @@ dataTimers[id] = setTimeout(() => { delete machineData[id]; updateDisplay(); + + // NOWE: Jeśli dane są przestarzałe, zakładamy, że WebSocket to "zombie". + // Zabijamy go ręcznie, co wywoła onclose i sprowokuje ponowne połączenie. + if (wsMap[id] && wsStatus[id] === "connected") { + console.warn(`Brak danych dla ${id} - ubijam ciche połączenie`); + wsMap[id].close(); + } }, DATA_STALE_MS); } @@ -311,6 +318,7 @@ ws.onopen = () => { wsStatus[id] = "connected"; refreshStatus(); + resetStaleTimer(id); // NOWE: Startujemy timer od razu po otwarciu }; ws.onmessage = (ev) => { @@ -329,6 +337,11 @@ ws.onerror = () => { wsStatus[id] = "error"; refreshStatus(); + + // NOWE: Jitter zapobiegający "Thundering Herd" + // Baza 5000ms + losowo od 0 do 3000ms + const reconnectDelay = RECONNECT_MS + Math.floor(Math.random() * 3000); + setTimeout(() => connect(id), reconnectDelay); }; ws.onclose = () => {