Control: disconnect streamwall socket on ping timeout

This can hopefully address a hung websocket preventing Streamwall from
reconnecting.
This commit is contained in:
Max Goodhart
2026-01-31 17:37:00 -08:00
parent 16f37cb5c2
commit a881634b85
2 changed files with 15 additions and 3 deletions

View File

@@ -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')

View File

@@ -469,8 +469,8 @@ async function main(argv: ReturnType<typeof parseArgs>) {
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', () => {