fix(weixin): guard live_adapter session reuse against cross-loop calls#14873
Open
Mr-z-j wants to merge 1 commit into
Open
fix(weixin): guard live_adapter session reuse against cross-loop calls#14873Mr-z-j wants to merge 1 commit into
Mr-z-j wants to merge 1 commit into
Conversation
When send_message is invoked from the gateway context, _run_async
spawns the coroutine in a fresh thread with a new event loop.
Reusing the live_adapter's ClientSession (bound to the gateway's
loop) causes aiohttp to raise:
Timeout context manager should be used inside a task
Fix: check that the session's bound event loop matches the current
running loop before reusing the live adapter. Falls back to creating
a new ClientSession when loops differ.
Collaborator
Author
|
您好,邮件已经收到;我会尽快和您联系。虽然这是一封自动回复邮件,但是我会每天查看邮箱!保证您的邮件在第一时间看到!
|
This was referenced Apr 26, 2026
Open
2 tasks
This was referenced May 1, 2026
Closed
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
When
send_messageis invoked from the gateway context (e.g., cron jobs or tool callbacks),_run_asyncspawns the coroutine in a fresh thread with a new event loop. Reusing thelive_adapter'sClientSession(which was bound to the gateway's original event loop) causesaiohttpto raise:This prevents Weixin proactive message delivery from working reliably in gateway mode.
Root Cause
aiohttp.ClientSessionis bound to the event loop that created it. In the current code (gateway/platforms/weixin.py),send_weixin_direct()unconditionally reuseslive_adapter._send_sessionif it exists and is not closed, without checking whether the current running loop matches the session's bound loop.Fix
Before reusing the live adapter's session, verify that
send_session._loopmatchesasyncio.get_running_loop(). If the loops differ (cross-loop call), fall back to creating a newClientSession.Changes
gateway/platforms/weixin.py: added_session_loop/_current_loopcheck insend_weixin_direct()Testing
send_messageto Weixin works from gateway context after the fixorigin/main(v0.11.0 + post-release commits)Related