From 809a42d172f1b04f6a0db2b323610e27d4f0dd74 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 2 May 2026 15:20:45 +0000 Subject: [PATCH] fix(gateway): start ping timer only after client authentication in ws-connection Agent-Logs-Url: https://github.com/openclaw/openclaw/sessions/30df0b08-4389-40c2-91e9-6f9189914f7b Co-authored-by: BunsDev <68980965+BunsDev@users.noreply.github.com> --- src/gateway/server/ws-connection.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/gateway/server/ws-connection.ts b/src/gateway/server/ws-connection.ts index 0a2dfaa212e..95a0bf9ffa3 100644 --- a/src/gateway/server/ws-connection.ts +++ b/src/gateway/server/ws-connection.ts @@ -267,16 +267,7 @@ export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnecti payload: { nonce: connectNonce, ts: Date.now() }, }); - const pingTimer = setInterval(() => { - if (!client) { - return; - } - try { - socket.ping(); - } catch { - // close() clears the timer; ping can race with a socket already entering CLOSING. - } - }, 25_000); + let pingTimer: ReturnType | undefined; const close = (code = 1000, reason?: string) => { if (closed) { @@ -284,7 +275,9 @@ export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnecti } closed = true; clearTimeout(handshakeTimer); - clearInterval(pingTimer); + if (pingTimer !== undefined) { + clearInterval(pingTimer); + } releasePreauthBudget(); if (client) { clients.delete(client); @@ -435,6 +428,13 @@ export function attachGatewayWsConnectionHandler(params: AttachGatewayWsConnecti releasePreauthBudget(); client = next; clients.add(next); + pingTimer = setInterval(() => { + try { + socket.ping(); + } catch { + // close() clears the timer; ping can race with a socket already entering CLOSING. + } + }, 25_000); return true; }, setHandshakeState: (next) => {