From 400106ec09ec9b90bed31ed0412410cc1d2f21ca Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 20 Feb 2025 13:09:51 -0600 Subject: [PATCH] Adjust WebSocket ping timeout to 15 seconds (#24339) * Adjust WebSocket ping timeout to 15 seconds 5 seconds was too low to prevent the UI from reloading when connecting the WebSocket during startup or on a high latancy connection This problem presented as the UI reloading over and over again because it could never respond to the ping in time on high latancy connections. At startup it usually only did this once so it went unnoticed in most cases. This ping was added in #18934 * Update connection-mixin.ts Co-authored-by: Jan-Philipp Benecke --------- Co-authored-by: Jan-Philipp Benecke --- src/state/connection-mixin.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/state/connection-mixin.ts b/src/state/connection-mixin.ts index 2a219abccb..fa017031dc 100644 --- a/src/state/connection-mixin.ts +++ b/src/state/connection-mixin.ts @@ -286,7 +286,10 @@ export const connectionMixin = >( clearInterval(this.__backendPingInterval); this.__backendPingInterval = setInterval(() => { if (this.hass?.connected) { - promiseTimeout(5000, this.hass?.connection.ping()).catch(() => { + // If the backend is busy, or the connection is latent, + // it can take more than 10 seconds for the ping to return. + // We give it a 15 second timeout to be safe. + promiseTimeout(15000, this.hass?.connection.ping()).catch(() => { if (!this.hass?.connected) { return; } @@ -296,7 +299,7 @@ export const connectionMixin = >( this.hass?.connection.reconnect(true); }); } - }, 10000); + }, 30000); } protected hassReconnected() {