mirror of
https://github.com/streamwall/streamwall.git
synced 2026-04-03 20:32:08 -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'
|
import { loadStorage, type StorageDB } from './storage.ts'
|
||||||
|
|
||||||
export const SESSION_COOKIE_NAME = 's'
|
export const SESSION_COOKIE_NAME = 's'
|
||||||
|
const STREAMWALL_PING_TIMEOUT_MS = 5 * 1000
|
||||||
|
|
||||||
interface Client {
|
interface Client {
|
||||||
clientId: string
|
clientId: string
|
||||||
@@ -171,7 +172,18 @@ async function initApp({ baseURL, clientStaticPath }: AppOptions) {
|
|||||||
|
|
||||||
const pingInterval = setInterval(() => {
|
const pingInterval = setInterval(() => {
|
||||||
ws.ping()
|
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', () => {
|
ws.on('close', () => {
|
||||||
console.log('Streamwall disconnected')
|
console.log('Streamwall disconnected')
|
||||||
|
|||||||
@@ -469,8 +469,8 @@ async function main(argv: ReturnType<typeof parseArgs>) {
|
|||||||
const ws = new ReconnectingWebSocket(argv.control.endpoint, [], {
|
const ws = new ReconnectingWebSocket(argv.control.endpoint, [], {
|
||||||
WebSocket,
|
WebSocket,
|
||||||
maxReconnectionDelay: 5000,
|
maxReconnectionDelay: 5000,
|
||||||
minReconnectionDelay: 1000 + Math.random() * 500,
|
minReconnectionDelay: 100 + Math.random() * 500,
|
||||||
reconnectionDelayGrowFactor: 1.1,
|
reconnectionDelayGrowFactor: 1.25,
|
||||||
})
|
})
|
||||||
ws.binaryType = 'arraybuffer'
|
ws.binaryType = 'arraybuffer'
|
||||||
ws.addEventListener('open', () => {
|
ws.addEventListener('open', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user