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