Repository navigation
fix: stop the worker loops from hanging on shutdown under Python 3.11 - #45
Merged
Merged
Conversation
The delivery and ephemeral worker loops waited with asyncio.wait_for, which on Python 3.11 can swallow a cancellation (the inner wait and the cancel race). stop() then awaited a loop that never ended, hanging the TestClient teardown (seen in CI as an intermittent Python 3.11 pytest hang, captured by the faulthandler dump). asyncio.timeout does not have that race. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VzFCH4ztqBYejkvLvFgnaq
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.
Root cause of the intermittent Python 3.11 CI hang
The first hang captured with the new diagnostics (faulthandler dump, run 44530786436) was stuck in
TestClient.__exit__ -> wait_shutdown: the app's lifespan shutdown never finished. The delivery and ephemeral worker loops waited withasyncio.wait_for, which on Python 3.11 can swallow a cancellation when the inner wait completes at the same instant.stop()then awaits a loop that never ends. Python 3.12 reimplementedwait_foronasyncio.timeout, which explains why only 3.11 hung.Fix
Use
asyncio.timeoutin both loops (app/services/delivery.py,app/services/ephemeral.py). No otherwait_forinapp/. In production the same race could have made a container stop wait for the shutdown timeout.Test plan
🤖 Generated with Claude Code
https://claude.ai/code/session_01VzFCH4ztqBYejkvLvFgnaq