fix(client/streamable_http): prevent infinite SSE reconnect loops with exponential backoff

Closed
AA
3mo ago
+6-5

Fixes #3356

Summary

In StreamableHTTPTransport.handle_get_stream, when an SSE stream closed normally or was terminated by upstream backpressure, the attempt counter was previously reset to 0 upon loop exit. If the server closed connections repeatedly, the client would bypass MAX_RECONNECTION_ATTEMPTS and enter an infinite reconnection storm.

Changes

  • Incremented attempt across clean disconnects to enforce global MAX_RECONNECTION_ATTEMPTS bounds.
  • Added exponential backoff (min(base_delay * 2^(attempt - 1), 30s)) to smooth traffic spikes and protect upstream servers.

Verification

  • Verified clean termination when attempt >= MAX_RECONNECTION_ATTEMPTS.
  • Verified backoff delay scaling across reconnection cycles.