Skip to content

fix(wecom): add CLOSING state to _wait_for_handshake terminal handler - #64707

Closed
mydearzsy wants to merge 2 commits into
NousResearch:mainfrom
mydearzsy:fix/wecom-wait-for-handshake-missing-closing
Closed

fix(wecom): add CLOSING state to _wait_for_handshake terminal handler#64707
mydearzsy wants to merge 2 commits into
NousResearch:mainfrom
mydearzsy:fix/wecom-wait-for-handshake-missing-closing

Conversation

@mydearzsy

Copy link
Copy Markdown

What

Adds aiohttp.WSMsgType.CLOSING to the terminal state check in _wait_for_handshake(), matching the identical fix already applied to _read_events() in #28311 (for issue #28293).

Why

_wait_for_handshake() was missing WSMsgType.CLOSING from its terminal state handler, causing WeCom reconnection to fail permanently with "closed during authentication" when the server sends a CLOSING frame during the authentication handshake.

When #28311 fixed _read_events() for issue #28293, _wait_for_handshake() was overlooked — both functions handle WebSocket messages and need to recognize all terminal states.

Impact

In production with multiple WeCom agents: after a mass restart event, agents that receive a CLOSING frame during the reconnection handshake get stuck in a permanent failure loop — manual pod restart is required to recover.

Fix

One-line change in plugins/platforms/wecom/adapter.py:

-            elif msg.type in {aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSE, aiohttp.WSMsgType.ERROR}:
+            elif msg.type in {aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.CLOSE, aiohttp.WSMsgType.ERROR, aiohttp.WSMsgType.CLOSING}:

Identical to the pattern already in _read_events() (line ~370).

Fixes: #64703

_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.

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
@alt-glitch alt-glitch added type/bug Something isn't working comp/plugins Plugin system and bundled plugins platform/wecom WeCom / WeChat Work adapter P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists platform/wecom WeCom / WeChat Work adapter sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(wecom): _wait_for_handshake missing CLOSING state causes permanent reconnect failure after mass restart

3 participants