fix: terminate streamable http sessions on shutdown#2952
Open
fengjikui wants to merge 1 commit into
Open
Conversation
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.
Summary
Fixes #2150.
Why
During
StreamableHTTPSessionManager.run()shutdown, stateful transports were cleared after cancelling the task group without first being terminated. Separately,StreamableHTTPServerTransport.terminate()cleaned request streams but left_sse_stream_writersopen. Active streaming responses could therefore be cancelled before their SSE streams were closed cleanly.Tests
uv run pytest tests/server/test_streamable_http_manager.py::test_run_terminates_active_transports_before_shutdown tests/server/test_streamable_http_manager.py::test_transport_terminate_closes_active_sse_writers -quv run pytest tests/server/test_streamable_http_manager.py -quv run pytest tests/shared/test_streamable_http.py::test_session_termination tests/shared/test_streamable_http.py::test_streamable_http_client_session_termination tests/shared/test_streamable_http.py::test_streamable_http_client_session_termination_204 tests/shared/test_streamable_http.py::test_close_sse_stream_callback_not_provided_for_old_protocol_version tests/shared/test_streamable_http.py::test_close_sse_stream_callback_not_provided_for_unknown_protocol_version -quv run ruff check src/mcp/server/streamable_http_manager.py src/mcp/server/streamable_http.py tests/server/test_streamable_http_manager.pyuv run ruff format --check src/mcp/server/streamable_http_manager.py src/mcp/server/streamable_http.py tests/server/test_streamable_http_manager.pyuv run python -m py_compile src/mcp/server/streamable_http_manager.py src/mcp/server/streamable_http.py tests/server/test_streamable_http_manager.pygit diff --check