Skip to content

fix(http): wait for session manager readiness before handling requests#315

Open
syf2211 wants to merge 1 commit into
tadata-org:mainfrom
syf2211:fix/259-mount-http-hang
Open

fix(http): wait for session manager readiness before handling requests#315
syf2211 wants to merge 1 commit into
tadata-org:mainfrom
syf2211:fix/259-mount-http-hang

Conversation

@syf2211

@syf2211 syf2211 commented Jun 27, 2026

Copy link
Copy Markdown

Summary

Replace the unreliable asyncio.sleep(0.1) startup delay in FastApiHttpSessionManager._ensure_session_manager_started() with an asyncio.Event that is signaled once StreamableHTTPSessionManager.run() has initialized its internal task group.

Motivation

Fixes #259. When using mount_http(), POST requests to /mcp could hang indefinitely because requests were handled before the StreamableHTTP message router was ready. A fixed 100ms sleep does not guarantee initialization on slower systems or under load.

Changes

  • Signal readiness from inside the run() context instead of sleeping
  • Set _manager_started only after readiness is confirmed (also closes a race where concurrent callers could proceed too early)
  • Propagate background startup failures via task.result()
  • Add unit test verifying _task_group is initialized after startup

Tests

  • uv run pytest tests/test_http_transport.py -q --no-cov — PASS
  • uv run pytest tests/test_http_real_transport.py::test_http_initialize_request -q --no-cov — PASS
  • uv run ruff check fastapi_mcp/transport/http.py tests/test_http_transport.py — PASS
  • uv run mypy fastapi_mcp/transport/http.py — PASS

Notes

Composer-2.5 review: APPROVE. No blocking issues found.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Replace the unreliable asyncio.sleep(0.1) startup delay with an event
signaled once StreamableHTTPSessionManager.run() has initialized its task
group. This prevents mount_http() requests from hanging when the message
router is not ready yet.

Fixes tadata-org#259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] mount_http() causes request to hang indefinitely

1 participant