From 0f902de75c3e4395836359f37aba57f1d09866b8 Mon Sep 17 00:00:00 2001 From: reagan Date: Fri, 8 Aug 2025 10:22:37 -0700 Subject: [PATCH] Send Keep-Alive ping immediately --- src/SignalR/clients/ts/signalr/src/HubConnection.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SignalR/clients/ts/signalr/src/HubConnection.ts b/src/SignalR/clients/ts/signalr/src/HubConnection.ts index 2487d0f0b558..07d2449dfe7b 100644 --- a/src/SignalR/clients/ts/signalr/src/HubConnection.ts +++ b/src/SignalR/clients/ts/signalr/src/HubConnection.ts @@ -726,7 +726,12 @@ export class HubConnection { { let nextPing = this._nextKeepAlive - new Date().getTime(); if (nextPing < 0) { - nextPing = 0; + if (this._connectionState === HubConnectionState.Connected) { + this._sendMessage(this._cachedPingMessage).catch((e) => { + this._logger.log(LogLevel.Warning, "Error sending keep-alive message" + e); + }); + return; + } } // The timer needs to be set from a networking callback to avoid Chrome timer throttling from causing timers to run once a minute