fix(weixin): wrap aiohttp requests in asyncio.create_task - #33445
fix(weixin): wrap aiohttp requests in asyncio.create_task#33445AaronWong1999 wants to merge 1 commit into
Conversation
…out context manager bug
|
Duplicate — this is the same Weixin aiohttp |
|
Hey @alt-glitch, thanks for connecting all these related issues and PRs — it's helpful to see the full picture. I took some time today to read through all the competing fixes (#14530, #17911, #18417, and mine) carefully, and I wanted to share my honest take on the landscape in case it helps move this forward. I have no strong attachment to any particular approach, but after comparing them I think #33445 might be the safest candidate for a first merge. Here's my reasoning: vs #14530 — The vs #17911 — Swapping vs #18417 — This one's actually conceptually right: ensuring coroutines run inside a proper The two aren't mutually exclusive — #18417 could absolutely land as a follow-up root-cause hardening after it's had more soak time, and I'd support that. But for an immediate fix that's been running in production without issues and won't accidentally regress Slack/Discord/Telegram/etc., I think the surgical approach is the right first step. Happy to take any feedback or adjust the patch if there's a preferred style. Appreciate you taking the time to look at this. |
|
Thanks for the focused Weixin fix. The reported timeout-context failure is already addressed on current main by a merged alternative, so this PR is now redundant.
This is an automated hermes-sweeper review. |
What does this PR do?
When running the Weixin platform gateway, sending messages can occasionally fail with:
RuntimeError: Timeout context manager should be used inside a taskThis happens because the
aiohttp.ClientSessionrequests (session.postandsession.get) useasyncio.timeoutinternally, but they were being awaited directly in the call stack outside of a properasyncio.Taskcontext. This PR wraps the inner HTTP calls withinasyncio.create_task()so that the timeout context manager is safely scoped within a task, preventing the crash.Why is it needed?
This bug prevents messages from being reliably delivered via Weixin, especially if there's a slight network delay triggering the timeout evaluation path. We noticed this in production where cron-delivered Weixin messages would repeatedly fail to send due to this exception.
How was it fixed?
Wrapped the core HTTP logic inside
_api_postand_api_getinside an_inner()async function, and returnedawait asyncio.create_task(_inner()).