fix(server): terminate streamable HTTP sessions on manager shutdown
Closed
BA
3mo ago+172+172+012345678901234567890123456789-2-2-0123456789
Summary
Fixes #2150.
Streamable HTTP sessions were not terminated during manager shutdown, and terminate() did not close active SSE writers. That left EventSourceResponse / ASGI callables incomplete on CTRL+C (uvicorn incomplete-response noise and resource leaks under multi-session hosts).
Changes
StreamableHTTPSessionManager.run()— callterminate()on active transports before cancelling the task group.StreamableHTTPServerTransport.terminate()— close all_sse_stream_writersviaclose_sse_stream()first so SSE responses can finish.- Regression tests for writer close + manager shutdown terminate.
Relation to existing work
- Open PR #2253 targets
v1.x, is older, and does not include the regression suite. This PR targetsmainwith tests. - Happy to close/adjust if maintainers prefer landing via #2253 or a different base.
Test plan
-
uv run pytest tests/server/test_streamable_http_manager.py::test_terminate_closes_active_sse_stream_writers -q -
uv run pytest tests/server/test_streamable_http_manager.py::test_manager_shutdown_terminates_active_sessions -q -
uv run pytest tests/server/test_streamable_http_manager.py -q(32 passed locally)