Skip to content

fix: enforce retry limit when SSE stream makes no progress#742

Merged
maciej-kisiel merged 4 commits intomodelcontextprotocol:mainfrom
majiayu000:fix-679-set-a-total-retry-limit-on-str-1231-0632
Feb 3, 2026
Merged

fix: enforce retry limit when SSE stream makes no progress#742
maciej-kisiel merged 4 commits intomodelcontextprotocol:mainfrom
majiayu000:fix-679-set-a-total-retry-limit-on-str-1231-0632

Conversation

@majiayu000
Copy link
Contributor

Fixes #679

Changes

  • Track last event ID to detect progress in SSE streams
  • Only reset retry counter when Last-Event-ID advances
  • Fail connection after exceeding maxRetries without progress

This implements Option 2 from the issue: progress-based retry limiting that prevents infinite retry loops while allowing long-running streams to continue as long as progress is made.

…extprotocol#679)

Previously, the StreamableClientTransport retry counter would reset
whenever a connection was re-established, which could lead to infinite
retry loops if a server continuously terminates connections without
making progress (advancing the Last-Event-ID).

This change tracks progress across retry attempts in handleSSE:
- The retry counter is only reset when the Last-Event-ID advances
- If maxRetries is exceeded without progress, the connection fails
- This implements Option 2 from the issue discussion

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: majiayu000 <1835304752@qq.com>
@findleyr
Copy link
Contributor

findleyr commented Jan 2, 2026

Thanks for this contribution, and sorry for the delay. I'll be catching up on PRs this weekend / next week.

@findleyr findleyr self-requested a review January 2, 2026 18:11
Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good. Just a couple nits in the test.

}

// Verify that we actually retried the expected number of times.
// We expect maxRetries+1 attempts because we increment before checking the limit.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, make this more assertive: assert that got == maxRetries+1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const maxRetries = 2

(more readable, and avoids some conversions below)

maciej-kisiel
maciej-kisiel previously approved these changes Jan 29, 2026
Copy link
Contributor

@findleyr findleyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @maciej-kisiel feel free to merge.

@maciej-kisiel maciej-kisiel merged commit cf88bda into modelcontextprotocol:main Feb 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set a total retry limit on streams, or enforce progress

4 participants

Comments