Skip to content

Commit 98c3c93

Browse files
committed
fix(gateway): add WebSocket ping keepalive to prevent idle connection drops
Made-with: Cursor
1 parent bd1c48e commit 98c3c93

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/gateway/server/ws-connection.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnecti
160160
let lastFrameType: string | undefined;
161161
let lastFrameMethod: string | undefined;
162162
let lastFrameId: string | undefined;
163+
const pingTimer = setInterval(() => {
164+
try {
165+
socket.ping();
166+
} catch {}
167+
}, 25_000);
163168

164169
const setCloseCause = (cause: string, meta?: Record<string, unknown>) => {
165170
if (!closeCause) {
@@ -207,6 +212,7 @@ export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnecti
207212
}
208213
closed = true;
209214
clearTimeout(handshakeTimer);
215+
clearInterval(pingTimer);
210216
releasePreauthBudget();
211217
if (client) {
212218
clients.delete(client);

0 commit comments

Comments
 (0)