Fix infinite retry loop in _handle_reconnection

Closed
CH
6mo ago
+5-2

Summary

  • Fixes _handle_reconnection resetting the attempt counter to 0 when an SSE stream ends without a complete response, which made MAX_RECONNECTION_ATTEMPTS ineffective and caused infinite retries
  • Changes line 426 to pass attempt + 1 instead of 0 so total reconnection attempts are tracked across recursions

Root Cause

When a reconnection succeeds at the HTTP level (200 OK) but the SSE stream drops before delivering a complete JSONRPCResponse, the method recursed with attempt=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

  • Existing tests pass (no behavioral change for streams that complete normally or fail at the connection level)
  • With the reproducer from #2393, the client now gives up after MAX_RECONNECTION_ATTEMPTS (2) instead of looping indefinitely

Fixes #2393