From 35717e82167209d228d2cd632e36e270b52cb1b6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 28 Mar 2025 09:32:00 -1000 Subject: [PATCH] Increase websocket_api allowed peak time to 10s (#141680) * Increase websocket_api allowed peak time to 10s fixes #141624 During integration reload or startup, we can end up sending a message for each entity being created for integrations that create them from an external source (ie MQTT) because the messages come in one at a time. This can overload the loop and/or client for more than 5s. While we have done significant work to optimize for this path, we are at the limit at what we can expect clients to be able to process in the time window, so increase the time window. * adjust test --- homeassistant/components/websocket_api/const.py | 2 +- tests/components/websocket_api/test_http.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/websocket_api/const.py b/homeassistant/components/websocket_api/const.py index a0d031834ae..fce85339430 100644 --- a/homeassistant/components/websocket_api/const.py +++ b/homeassistant/components/websocket_api/const.py @@ -21,7 +21,7 @@ type AsyncWebSocketCommandHandler = Callable[ DOMAIN: Final = "websocket_api" URL: Final = "/api/websocket" PENDING_MSG_PEAK: Final = 1024 -PENDING_MSG_PEAK_TIME: Final = 5 +PENDING_MSG_PEAK_TIME: Final = 10 # Maximum number of messages that can be pending at any given time. # This is effectively the upper limit of the number of entities # that can fire state changes within ~1 second. diff --git a/tests/components/websocket_api/test_http.py b/tests/components/websocket_api/test_http.py index 03e30c11ee9..370aab1067a 100644 --- a/tests/components/websocket_api/test_http.py +++ b/tests/components/websocket_api/test_http.py @@ -241,7 +241,7 @@ async def test_pending_msg_peak( instance: http.WebSocketHandler = cast(http.WebSocketHandler, setup_instance) # Fill the queue past the allowed peak - for _ in range(10): + for _ in range(20): instance._send_message({"overload": "message"}) async_fire_time_changed( @@ -251,7 +251,7 @@ async def test_pending_msg_peak( msg = await websocket_client.receive() assert msg.type is WSMsgType.CLOSE assert "Client unable to keep up with pending messages" in caplog.text - assert "Stayed over 5 for 5 seconds" in caplog.text + assert "Stayed over 5 for 10 seconds" in caplog.text assert "overload" in caplog.text