fix(weixin): avoid cross-loop aiohttp session reuse in send_weixin_direct - #35237
Closed
betterMax wants to merge 1 commit into
Closed
fix(weixin): avoid cross-loop aiohttp session reuse in send_weixin_direct#35237betterMax wants to merge 1 commit into
betterMax wants to merge 1 commit into
Conversation
…rect When the gateway is running, _run_async() spins up a new thread with a fresh event loop via asyncio.run(). The send_weixin_direct() path A tries to reuse the live adapter's aiohttp session, but that session is bound to the gateway's event loop. Using an aiohttp session from a different loop triggers: RuntimeError: Timeout context manager should be used inside a task This makes send_message tool calls from gateway context fail for both text and media delivery, while normal gateway replies work fine. Fix: check that the session's event loop matches the current loop before attempting to reuse it. When loops differ, fall through to path B which creates a temporary session on the current loop. Tested: .png (400KB), .md (2KB), .zip (652KB), .pdf (552KB), 1MB and 5MB binary files all send successfully after the fix.
Collaborator
19 tasks
Contributor
|
Thanks for the focused cross-loop fix. This is already implemented on current
Closing as implemented on main. |
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
When the gateway is running,
send_messagetool calls to Weixin always fail with:This affects both text and media delivery. Normal gateway replies work fine.
Root Cause
_run_async()(called bysend_message_tool) detects a running event loop and spins up a new thread withasyncio.run(), creating a fresh event loop. However,send_weixin_direct()path A reuses the_LIVE_ADAPTERSaiohttp session, which is bound to the gateway's event loop. aiohttp raisesRuntimeErrorwhen a session is used from a different loop than the one it was created on.This explains the intermittent behavior:
send_messagetool → cross-loop conflict → failsFix
Add a loop compatibility check before reusing the live adapter session. When loops differ, fall through to path B which creates a temporary session on the current loop.
Testing