Handle Errno::ECONNRESET in SSE stream operations#249
Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Handle Errno::ECONNRESET in SSE stream operations#249koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Errno::ECONNRESET in SSE stream operations#249koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
9 tasks
atesgoral
previously approved these changes
Mar 1, 2026
Contributor
atesgoral
left a comment
There was a problem hiding this comment.
Love the comprehensive tests!
`Errno::ECONNRESET` is a `SystemCallError`, not an `IOError`, so it was not caught by the existing `rescue IOError, Errno::EPIPE` clauses. When a client disconnected with a TCP RST during SSE notification broadcast, the unhandled exception aborted the entire broadcast loop, causing notifications to be lost for all remaining sessions. This caused the `tools-call-with-logging` conformance scenario to fail in CI (modelcontextprotocol#248), where stale sessions from prior scenarios triggered `ECONNRESET` on the first notification write, aborting the broadcast and losing log notifications. Add `Errno::ECONNRESET` to all four rescue clauses in `StreamableHTTPTransport`: `send_notification` (targeted and broadcast), `send_response_to_stream`, and `send_keepalive_ping`.
a1ad406 to
9c1c249
Compare
Member
Author
|
There were conflicts in the source code, so it has been rebased onto the latest |
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.
Motivation and Context
Errno::ECONNRESETis aSystemCallError, not anIOError, so it was not caught by the existingrescue IOError, Errno::EPIPEclauses. When a client disconnected with a TCP RST during SSE notification broadcast, the unhandled exception aborted the entire broadcast loop, causing notifications to be lost for all remaining sessions.This caused the
tools-call-with-loggingconformance scenario to fail in CI (#248), where stale sessions from prior scenarios triggeredECONNRESETon the first notification write, aborting the broadcast and losing log notifications.Add
Errno::ECONNRESETto all four rescue clauses inStreamableHTTPTransport:send_notification(targeted and broadcast),send_response_to_stream, andsend_keepalive_ping.How Has This Been Tested?
Added a repro test to verify the fix and prevent regression.
Breaking Changes
None.
Types of changes
Checklist