Skip to content

Commit 2efbb42

Browse files
Fix infinite retry loop in StreamableHTTP _handle_reconnection
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 #2393
1 parent d5b9155 commit 2efbb42

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/mcp/client/streamable_http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,9 @@ async def _handle_reconnection(
421421
await event_source.response.aclose()
422422
return
423423

424-
# Stream ended again without response - reconnect again (reset attempt counter)
424+
# Stream ended again without response - reconnect again
425425
logger.info("SSE stream disconnected, reconnecting...")
426-
await self._handle_reconnection(ctx, reconnect_last_event_id, reconnect_retry_ms, 0)
426+
await self._handle_reconnection(ctx, reconnect_last_event_id, reconnect_retry_ms, attempt + 1)
427427
except Exception as e: # pragma: no cover
428428
logger.debug(f"Reconnection failed: {e}")
429429
# Try to reconnect again if we still have an event ID

0 commit comments

Comments
 (0)