Skip to content

fix(http): wait for session manager readiness before handling requests (adopted from #315) - #340

Open
K4bain wants to merge 1 commit into
tadata-org:mainfrom
K4bain:fix/http-startup-readiness
Open

fix(http): wait for session manager readiness before handling requests (adopted from #315)#340
K4bain wants to merge 1 commit into
tadata-org:mainfrom
K4bain:fix/http-startup-readiness

Conversation

@K4bain

@K4bain K4bain commented Aug 27, 2026

Copy link
Copy Markdown

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

  • New tests/test_http_transport.py asserts that after _ensure_session_manager_started() the manager is started and its internal task group is initialized, then shuts down cleanly. (Note: this assertion happens to pass on main too since the 0.1s sleep usually elapses before the check on CI-class machines — the fix makes the readiness deterministic rather than timing-lucky; the test is regression coverage for the [BUG] mount_http() causes request to hang indefinitely #259 race.)
  • Full unit suite: 70 passed (69 existing + 1 new).

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.

_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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant