fix: handle transport exceptions and ensure proper cleanup of in-flig…#1
Merged
EiffL merged 1 commit intomainEiffL/python-sdk:mainfrom Aug 28, 2025
streamable_http_disconnectEiffL/python-sdk:streamable_http_disconnectCopy head branch name to clipboard
Merged
fix: handle transport exceptions and ensure proper cleanup of in-flig…#1EiffL merged 1 commit intomainEiffL/python-sdk:mainfrom streamable_http_disconnectEiffL/python-sdk:streamable_http_disconnectCopy head branch name to clipboard
EiffL merged 1 commit intomainEiffL/python-sdk:mainfrom
streamable_http_disconnectEiffL/python-sdk:streamable_http_disconnectCopy head branch name to clipboard
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.
…ht requests
This pull request improves the robustness of the client-server communication by ensuring that transport-level disconnects are handled gracefully and do not leave requests hanging. It also adds a new test to verify that clients receive an appropriate error when the server goes down mid-request.
Transport error handling improvements:
src/mcp/client/streamable_http.py, exceptions encountered while reading the SSE stream are now forwarded to the session read stream, which is then closed to signal that no further messages will arrive.src/mcp/shared/session.py, when a transport-level exception is received, it is forwarded to the incoming handler and all in-flight requests are failed with aCONNECTION_CLOSEDerror. The receive loop then exits, preventing clients from hanging indefinitely.Testing enhancements:
test_streamable_http_mid_call_disconnectintests/shared/test_streamable_http.pyto verify that a client receives aCONNECTION_CLOSEDerror if the server dies during a long-running tool call, rather than hanging.