From a881634b8514f74083c0f08ba710bc4bcd6353d7 Mon Sep 17 00:00:00 2001 From: Max Goodhart Date: Sat, 31 Jan 2026 17:37:00 -0800 Subject: [PATCH] Control: disconnect streamwall socket on ping timeout This can hopefully address a hung websocket preventing Streamwall from reconnecting. --- packages/streamwall-control-server/src/index.ts | 14 +++++++++++++- packages/streamwall/src/main/index.ts | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/streamwall-control-server/src/index.ts b/packages/streamwall-control-server/src/index.ts index 7952819..7fc9732 100644 --- a/packages/streamwall-control-server/src/index.ts +++ b/packages/streamwall-control-server/src/index.ts @@ -20,6 +20,7 @@ import { Auth, StateWrapper, uniqueRand62 } from './auth.ts' import { loadStorage, type StorageDB } from './storage.ts' export const SESSION_COOKIE_NAME = 's' +const STREAMWALL_PING_TIMEOUT_MS = 5 * 1000 interface Client { clientId: string @@ -171,7 +172,18 @@ async function initApp({ baseURL, clientStaticPath }: AppOptions) { const pingInterval = setInterval(() => { ws.ping() - }, 5 * 1000) + const pongTimeout = setTimeout(() => { + if (ws.readyState === ws.OPEN) { + console.warn( + `Streamwall timeout: no pong within ${STREAMWALL_PING_TIMEOUT_MS}ms. Closing connection.`, + ) + ws.close() + } + }, STREAMWALL_PING_TIMEOUT_MS) + ws.once('pong', () => { + clearTimeout(pongTimeout) + }) + }, STREAMWALL_PING_TIMEOUT_MS) ws.on('close', () => { console.log('Streamwall disconnected') diff --git a/packages/streamwall/src/main/index.ts b/packages/streamwall/src/main/index.ts index 91de3e9..65455a2 100644 --- a/packages/streamwall/src/main/index.ts +++ b/packages/streamwall/src/main/index.ts @@ -469,8 +469,8 @@ async function main(argv: ReturnType) { const ws = new ReconnectingWebSocket(argv.control.endpoint, [], { WebSocket, maxReconnectionDelay: 5000, - minReconnectionDelay: 1000 + Math.random() * 500, - reconnectionDelayGrowFactor: 1.1, + minReconnectionDelay: 100 + Math.random() * 500, + reconnectionDelayGrowFactor: 1.25, }) ws.binaryType = 'arraybuffer' ws.addEventListener('open', () => {