Skip to content

bug(client/streamable_http): prevent infinite SSE reconnect loops with bounded exponential backoff #3356

Description

@AAH20

Problem

In StreamableHTTPTransport.handle_get_stream, when an SSE stream disconnects or closes (server-side EOF/backpressure), attempt was reset to 0 upon exit. If an upstream server disconnects continuously, the client bypasses MAX_RECONNECTION_ATTEMPTS and enters an infinite reconnection loop without backoff jitter.

Expected Behavior

The client should respect MAX_RECONNECTION_ATTEMPTS on stream disconnects and apply exponential backoff to prevent thundering-herd storms on upstream MCP servers.

Activity

  1. added
    v2Affects the v2 line (2.x on main)
    v1Affects the v1.x maintenance line
    on Aug 21, 2026
  2. jagadeepmamidi commented on Sep 1, 2026

    @jagadeepmamidi

    I can reproduce the reconnect-loop behavior described here. I’d be interested in working on a focused fix that keeps the reconnection attempt count bounded across SSE disconnects, applies the existing backoff behavior, and adds regression coverage for repeated disconnects. Happy to work on this if the approach aligns with what you have in mind.

  3. tk1475 commented on Sep 25, 2026

    @tk1475

    I think this is the same bug as #3257. In handle_get_stream (src/mcp/client/streamable_http.py, around L252-253 on main and L310-311 on v1.x), a GET stream that ends without an exception sets attempt = 0. So a server that keeps closing the stream cleanly never pushes the counter toward MAX_RECONNECTION_ATTEMPTS, and the client reconnects forever. #3087 (currently a draft) already targets this by not resetting the counter on empty connections, so it may be worth tracking or reviewing that PR rather than opening a separate fix. @jagadeepmamidi, if you want to help, the regression test you described would probably be a useful addition there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v1Affects the v1.x maintenance linev2Affects the v2 line (2.x on main)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions