fix(qqbot): stop 100% CPU spin when WebSocket is closed but not None (#31193, #31771) (#40574)

_read_events() returned normally when self._ws was closed-but-non-None
(the while-condition is false on entry). _listen_loop treats a normal
return as a clean read, resets backoff to 0, and immediately retries —
a tight busy-loop pinning CPU. Raising on entry routes it through the
reconnect/backoff path instead.

Co-authored-by: xushibo <xushibo@users.noreply.github.com>
Co-authored-by: cnfi <cnfi@users.noreply.github.com>
This commit is contained in:
Teknium
2026-06-06 18:44:44 -07:00
committed by GitHub
co-authored by xushibo cnfi
parent 5b55f4fe8e
commit 3eeca4613d
2 changed files with 30 additions and 0 deletions
+6
View File
@@ -681,6 +681,12 @@ class QQAdapter(BasePlatformAdapter):
"""Read WebSocket frames until connection closes."""
if not self._ws:
raise RuntimeError("WebSocket not connected")
if self._ws.closed:
# A closed-but-non-None ws makes the while-condition false on entry,
# so this would return normally — which _listen_loop treats as a
# clean read and immediately retries with backoff reset to 0,
# producing a 100% CPU spin. Raise so the reconnect/backoff path runs.
raise RuntimeError("WebSocket closed")
while self._running and self._ws and not self._ws.closed:
msg = await self._ws.receive()