fix(qqbot): prevent busy-loop when WebSocket is closed but not None - #40497
Closed
xushibo wants to merge 1 commit into
Closed
fix(qqbot): prevent busy-loop when WebSocket is closed but not None#40497xushibo wants to merge 1 commit into
xushibo wants to merge 1 commit into
Conversation
_read_events() returned silently when self._ws was a closed aiohttp WebSocket (non-None but .closed==True), causing _listen_loop() to reset backoff_idx and immediately re-enter — a tight CPU-bound loop consuming 100% CPU indefinitely. This fix adds an early check: if self._ws.closed is True on entry, raise RuntimeError, which is caught by the existing reconnect/backoff handler in _listen_loop(). Closes NousResearch#31771 Closes NousResearch#31193
Collaborator
23 tasks
|
Reproduction:
Confirmation on production (twice): Main thread stuck in Same behavior was fixed in WeCom adapter (commit 8dca287, 2026-05-18): aiohttp Environment where reproduced:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
After QQBot WebSocket disconnect and a failed reconnect attempt, the gateway process enters a tight CPU-bound loop consuming 100% CPU indefinitely with no further reconnect logging.
Fixes #31771
Fixes #31193
Root Cause
In
gateway/platforms/qqbot/adapter.py,_read_events()returns silently whenself._wsis a closed aiohttp WebSocket (non-None but.closed==True). The outer_listen_loop()sees this as a normal return, resetsbackoff_idxto 0, and immediately re-enters — a zero-delay spin.Fix
Add an early guard: if
self._ws.closedis True on entry to_read_events(), raiseRuntimeError, which is caught by the existing reconnect/backoff handler in_listen_loop().Change: 2 lines added to
gateway/platforms/qqbot/adapter.pyHow to Verify
Test Plan
Risk Assessment
Low — the added check only fires when WebSocket is already in a terminal state. The existing exception handler in
_listen_loop()already handlesRuntimeErrorwith proper backoff and reconnect logic. No change to the happy path.