fix(weixin): replace aiohttp timeout with asyncio.wait_for for cross-thread safety - #17911
Closed
rj-chenlinfeng wants to merge 1 commit into
Closed
rj-chenlinfeng wants to merge 1 commit into
rj-chenlinfeng wants to merge 1 commit into
Conversation
Contributor
This was referenced Apr 30, 2026
This was referenced May 27, 2026
Collaborator
|
This looks implemented on current Evidence:
The maintainer comment here correctly noted this belonged to a cluster of related WeChat timeout PRs; main appears to have picked and shipped this approach. |
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.
Problem
When cron jobs deliver messages via
asyncio.run_coroutine_threadsafe(), the WeChat iLink platform adapter intermittently fails with:This is because
aiohttp.ClientTimeoutrelies onBaseTimerContextwhich callsasyncio.current_task()internally. When a coroutine is submitted from a non-event-loop thread (e.g., cron scheduler thread), a race condition can causecurrent_task()to returnNone, triggering the error.Solution
Replace
aiohttp.ClientTimeoutwithasyncio.wait_for()in_api_post()and_api_get().asyncio.wait_for()is a pure-asyncio timeout mechanism that does not depend on task context and is safe for cross-thread coroutine submission viarun_coroutine_threadsafe().Changes
gateway/platforms/weixin.py:_api_post()and_api_get()now wrap the HTTP call in an inner coroutine and useasyncio.wait_for()for timeout control instead of passingtimeout=tosession.post()/session.get().Testing
ast.parsepasses)