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
pull/90445/head
J. Nick Koston 2023-05-14 11:22:19 -05:00 committed by GitHub
parent e073f091b1
commit 2848f8648d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -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()

View File

@ -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(