mirror of
https://github.com/streamwall/streamwall.git
synced 2026-04-03 12:22:09 -04:00
Control: disconnect streamwall socket on ping timeout
This can hopefully address a hung websocket preventing Streamwall from reconnecting.
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user