Skip to content

fix(wecom): handle WSMsgType.CLOSING to prevent CPU spin (#28286)#28311

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3ad7d98a
May 19, 2026
Merged

fix(wecom): handle WSMsgType.CLOSING to prevent CPU spin (#28286)#28311
teknium1 merged 1 commit into
mainfrom
hermes/hermes-3ad7d98a

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Salvage of #28286 by @02356abc.

What: Treat aiohttp.WSMsgType.CLOSING as 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.

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>
@teknium1 teknium1 merged commit 8dca287 into main May 19, 2026
4 checks passed
@teknium1 teknium1 deleted the hermes/hermes-3ad7d98a branch May 19, 2026 02:32
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-3ad7d98a vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 8814 on HEAD, 8813 on base (🆕 +1)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 4631 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/wecom WeCom / WeChat Work adapter labels May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(gateway): WeCom gateway CPU spin when WebSocket enters CLOSING state

3 participants