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>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-02 15:20:45 +00:00
committed by Val Alexander
parent 99f12b8c4d
commit 809a42d172

View File

@@ -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<typeof setInterval> | 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) => {