websocket connection fixes
This commit is contained in:
@@ -292,6 +292,13 @@
|
|||||||
dataTimers[id] = setTimeout(() => {
|
dataTimers[id] = setTimeout(() => {
|
||||||
delete machineData[id];
|
delete machineData[id];
|
||||||
updateDisplay();
|
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);
|
}, DATA_STALE_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,6 +318,7 @@
|
|||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
wsStatus[id] = "connected";
|
wsStatus[id] = "connected";
|
||||||
refreshStatus();
|
refreshStatus();
|
||||||
|
resetStaleTimer(id); // NOWE: Startujemy timer od razu po otwarciu
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = (ev) => {
|
ws.onmessage = (ev) => {
|
||||||
@@ -329,6 +337,11 @@
|
|||||||
ws.onerror = () => {
|
ws.onerror = () => {
|
||||||
wsStatus[id] = "error";
|
wsStatus[id] = "error";
|
||||||
refreshStatus();
|
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 = () => {
|
ws.onclose = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user