From 2848f8648d3251a4a278aceffaa81ba9c2c64c7a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 14 May 2023 11:22:19 -0500 Subject: [PATCH] Log last message when websocket reaches peak limit (#93038) When we hit the absolute limit, we would log the last messages as it was key to finding out the source. We now do the same when we hit the peak limit --- homeassistant/components/websocket_api/http.py | 5 +++-- tests/components/websocket_api/test_http.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/websocket_api/http.py b/homeassistant/components/websocket_api/http.py index 7671d0ceaef..310247709f8 100644 --- a/homeassistant/components/websocket_api/http.py +++ b/homeassistant/components/websocket_api/http.py @@ -172,7 +172,7 @@ class WebSocketHandler: ( "%s: Client unable to keep up with pending messages. Reached %s pending" " messages. The system's load is too high or an integration is" - " misbehaving. Last message was: %s" + " misbehaving; Last message was: %s" ), self.description, MAX_PENDING_MSG, @@ -209,11 +209,12 @@ class WebSocketHandler: ( "%s: Client unable to keep up with pending messages. Stayed over %s for %s" " seconds. The system's load is too high or an integration is" - " misbehaving" + " misbehaving; Last message was: %s" ), self.description, PENDING_MSG_PEAK, PENDING_MSG_PEAK_TIME, + self._message_queue[-1], ) self._cancel() diff --git a/tests/components/websocket_api/test_http.py b/tests/components/websocket_api/test_http.py index 8e47e7fca2e..7c008f7515b 100644 --- a/tests/components/websocket_api/test_http.py +++ b/tests/components/websocket_api/test_http.py @@ -70,7 +70,7 @@ async def test_pending_msg_peak( # Fill the queue past the allowed peak for _ in range(10): - instance._send_message({}) + instance._send_message({"overload": "message"}) async_fire_time_changed( hass, utcnow() + timedelta(seconds=const.PENDING_MSG_PEAK_TIME + 1) @@ -79,7 +79,8 @@ async def test_pending_msg_peak( msg = await websocket_client.receive() assert msg.type == WSMsgType.close assert "Client unable to keep up with pending messages" in caplog.text - assert "Stayed over 5 for 5 seconds" + assert "Stayed over 5 for 5 seconds" in caplog.text + assert "overload" in caplog.text async def test_pending_msg_peak_recovery(