fix(wecom): handle WSMsgType.CLOSING to prevent CPU spin (#28286) - #28311
Merged
Conversation
The WeCom adapter's _read_events() loop only handled CLOSE, CLOSED,
and ERROR websocket message types. When the server initiates a graceful
shutdown, aiohttp returns WSMsgType.CLOSING before the connection is
fully closed. This message type was not handled, causing the receive()
call to return immediately in a tight loop while self._ws.closed
remained False. The result was 100% CPU usage on the asyncio event loop.
Add WSMsgType.CLOSING to the set of terminal message types that raise
RuntimeError("WeCom websocket closed"), allowing _listen_loop() to
enter its normal reconnect backoff path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
🔎 Lint report:
|
This was referenced Jun 8, 2026
19 tasks
This was referenced Jul 15, 2026
mydearzsy
added a commit
to mydearzsy/hermes-agent
that referenced
this pull request
Aug 4, 2026
_wait_for_handshake() was missing aiohttp.WSMsgType.CLOSING from its terminal state check, causing WeCom reconnection to fail permanently after mass restart when the server sends a CLOSING frame during the authentication handshake. - Adds CLOSING to _wait_for_handshake() terminal handler (1 line) - Adds three regression tests for CLOSING/CLOSED/ERROR frames - All 51 existing wecom tests still pass This mirrors the identical fix already applied to _read_events() in NousResearch#28311 (for issue NousResearch#28293), which was overlooked in _wait_for_handshake(). Fixes: NousResearch#64703
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.
Salvage of #28286 by @02356abc.
What: Treat
aiohttp.WSMsgType.CLOSINGas a terminal state in WeCom gateway's_read_events()loop instead of falling through and re-reading immediately, which spins CPU until the underlying socket closes.Why: When the WeCom WebSocket enters CLOSING state, the existing code didn't match any of the recognized termination types, so the loop tight-spun the event-read path until the WS reached CLOSED.
Original PR: #28286
Fixes #28293.