Fix infinite retry loop in _handle_reconnection#2397
Open
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Fix infinite retry loop in _handle_reconnection#2397Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
When a reconnection succeeds at the HTTP level but the SSE stream ends without delivering a complete response, _handle_reconnection recursed with attempt=0, resetting the counter and making MAX_RECONNECTION_ATTEMPTS ineffective. This caused the client to retry forever if the server repeatedly accepted connections but dropped streams. Pass attempt + 1 instead of 0 so total reconnection attempts are properly tracked across recursions. Fixes modelcontextprotocol#2393
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
_handle_reconnectionresetting theattemptcounter to0when an SSE stream ends without a complete response, which madeMAX_RECONNECTION_ATTEMPTSineffective and caused infinite retriesattempt + 1instead of0so total reconnection attempts are tracked across recursionsRoot Cause
When a reconnection succeeds at the HTTP level (200 OK) but the SSE stream drops before delivering a complete
JSONRPCResponse, the method recursed withattempt=0. Only the exception path (connection failure) incremented the counter. A server that accepts connections but drops streams caused the client to retry forever at 1-second intervals.Test plan
MAX_RECONNECTION_ATTEMPTS(2) instead of looping indefinitelyFixes #2393