Compare commits

..
1 Commits
Author SHA1 Message Date
MoepchiandClaude Opus 5.5 9c67471b49 gateway: idle timeout applies to sockets opened after a change
Each socket keeps the IDLE_TIMEOUT_MINUTES it was told in its hello.
Raising it from 0 in the admin panel used to drop already connected
pages after a few minutes without asking, since they never learned they
have to send "active".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
2026-11-30 23:34:06 +00:00
+8 -4
View File
@@ -626,6 +626,10 @@ interface HeartbeatState {
isAlive: boolean;
/** Last "active" message (user input in the page) or connect. */
lastActive: number;
/** Idle timeout this socket was told in its hello. A later change in the
* admin panel applies to new sockets only: older pages don't know they
* must send "active" and would be dropped without being asked. */
idleMs: number;
}
/** IDLE_TIMEOUT_MINUTES in ms, 0 = off. Read per check, the admin panel changes it live. */
@@ -656,8 +660,7 @@ const heartbeatTimer = setInterval(() => {
socket.terminate();
continue;
}
const idleMs = idleTimeoutMs();
if (idleMs > 0 && Date.now() - state.lastActive > idleMs + IDLE_GRACE_MS) {
if (state.idleMs > 0 && Date.now() - state.lastActive > state.idleMs + IDLE_GRACE_MS) {
// Close handler disconnects the TS session; the message tells the page
// this was deliberate, so it doesn't auto-reconnect.
socket.send('{"type":"idleTimeout"}');
@@ -748,16 +751,17 @@ wss.on("connection", (socket: WebSocket, req: IncomingMessage) => {
// pulled, so the browser must not assume a feature exists just because it
// knows about it. A gateway without "hello" (before v0.15) supports the
// v0.14 feature set, streaming included; anything newer gets a name here.
const idleMs = idleTimeoutMs();
socket.send(
JSON.stringify({
type: "hello",
features: gatewayFeatures(),
iceServers: turnServers(),
idleTimeoutMinutes: idleTimeoutMs() / 60_000,
idleTimeoutMinutes: idleMs / 60_000,
}),
);
heartbeats.set(socket, { isAlive: true, lastActive: Date.now() });
heartbeats.set(socket, { isAlive: true, lastActive: Date.now(), idleMs });
socket.on("pong", () => {
const state = heartbeats.get(socket);
if (state) state.isAlive = true;