fix(http): wait for session manager readiness before handling requests (adopted from #315) - #340
Open
K4bain wants to merge 1 commit into
Open
fix(http): wait for session manager readiness before handling requests (adopted from #315)#340K4bain wants to merge 1 commit into
K4bain wants to merge 1 commit into
Conversation
_ensure_session_manager_started() slept a fixed 0.1s after creating the background task, which can let requests arrive before the session manager's task group (and message router) is initialized (tadata-org#259). Replace the sleep with an asyncio.Event set inside the manager's run() context, await it, and surface any startup error by re-raising the task result. Adopted from tadata-org#315 (original patch by @syf2211).
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.
Adopted from #315 (original patch by @syf2211) — rebased onto current main and verified.
Why this is needed
After creating the background task that runs the session manager, _ensure_session_manager_started() just sleeps a fixed 0.1s. Under load or on slow event loops the manager's task group / message router may not be initialized when the first request is dispatched — the race behind #259.
The fix replaces the sleep with an asyncio.Event that is set inside async with self._session_manager.run(), then awaits it. If the manager task dies during startup, the event is set in the exception path and the task result is re-raised, so startup failures surface immediately instead of hanging or half-working.
Verification
mount_http()causes request to hang indefinitely #259 race.)Note for maintainers: #339 (adopted from #311) restructures the same file around lifespan startup — whichever lands second will need a small rebase, they are compatible in intent.
Credit to @syf2211 for the original report and patch in #315.