From 439e2d76b11d2355c552c8a577d0e85fc7262808 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 25 May 2024 13:16:44 -1000 Subject: [PATCH] tweak for chrome since it works great in firefox but chrome cannot handle it --- homeassistant/components/websocket_api/const.py | 1 + homeassistant/components/websocket_api/http.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/websocket_api/const.py b/homeassistant/components/websocket_api/const.py index af629cb2927..acedd59234d 100644 --- a/homeassistant/components/websocket_api/const.py +++ b/homeassistant/components/websocket_api/const.py @@ -22,6 +22,7 @@ type AsyncWebSocketCommandHandler = Callable[ DOMAIN: Final = "websocket_api" URL: Final = "/api/websocket" PENDING_MSG_PEAK: Final = 1024 +READY_FUTURE_MAX_MESSAGES: Final = 128 PENDING_MSG_PEAK_TIME: Final = 5 # Maximum number of messages that can be pending at any given time. # This is effectively the upper limit of the number of entities diff --git a/homeassistant/components/websocket_api/http.py b/homeassistant/components/websocket_api/http.py index 0c493cce201..cbe6452507e 100644 --- a/homeassistant/components/websocket_api/http.py +++ b/homeassistant/components/websocket_api/http.py @@ -26,6 +26,7 @@ from .const import ( MAX_PENDING_MSG, PENDING_MSG_PEAK, PENDING_MSG_PEAK_TIME, + READY_FUTURE_MAX_MESSAGES, SIGNAL_WEBSOCKET_CONNECTED, SIGNAL_WEBSOCKET_DISCONNECTED, URL, @@ -247,7 +248,9 @@ class WebSocketHandler: We will release the ready future if the queue did not grow since the last time we tried to release the ready future. - If we reach the peak, we will release the ready future immediately. + If we reach READY_FUTURE_MAX_MESSAGES, we will release the ready + future immediately so avoid the messages getting to large which + can cause Chrome to stall (not not firefox). """ if ( not (ready_future := self._ready_future) @@ -256,10 +259,7 @@ class WebSocketHandler: ): self._release_ready_queue_size = 0 return - # If we are below the peak and there are new messages in the queue - # since the last time we tried to release the ready future, we try again - # later so we can coalesce more messages. - if queue_size > self._release_ready_queue_size < PENDING_MSG_PEAK: + if queue_size > self._release_ready_queue_size < READY_FUTURE_MAX_MESSAGES: self._release_ready_queue_size = queue_size self._loop.call_soon(self._release_ready_future_or_reschedule) return