René's URL Explorer Experiment


Title: StreamableHTTP client: _handle_reconnection resets attempt counter to 0, causing infinite retry loop · Issue #2393 · modelcontextprotocol/python-sdk · GitHub

Open Graph Title: StreamableHTTP client: _handle_reconnection resets attempt counter to 0, causing infinite retry loop · Issue #2393 · modelcontextprotocol/python-sdk

X Title: StreamableHTTP client: _handle_reconnection resets attempt counter to 0, causing infinite retry loop · Issue #2393 · modelcontextprotocol/python-sdk

Description: Bug Description _handle_reconnection() in streamable_http.py resets the attempt counter to 0 on line 494 when a reconnection succeeds but the stream ends without delivering a complete response. This makes MAX_RECONNECTION_ATTEMPTS ineffe...

Open Graph Description: Bug Description _handle_reconnection() in streamable_http.py resets the attempt counter to 0 on line 494 when a reconnection succeeds but the stream ends without delivering a complete response. Thi...

X Description: Bug Description _handle_reconnection() in streamable_http.py resets the attempt counter to 0 on line 494 when a reconnection succeeds but the stream ends without delivering a complete response. Thi...

Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2393

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"StreamableHTTP client: _handle_reconnection resets attempt counter to 0, causing infinite retry loop","articleBody":"## Bug Description\n\n`_handle_reconnection()` in `streamable_http.py` resets the `attempt` counter to `0` on line 494 when a reconnection succeeds but the stream ends without delivering a complete response. This makes `MAX_RECONNECTION_ATTEMPTS` ineffective — the counter only applies to consecutive exceptions, not total reconnection attempts. If the server accepts the connection but the stream drops repeatedly, the client retries forever.\n\n## Reproduction\n\n**MCP version:** 1.26.0 (also confirmed unpatched in 1.27.0 `main` branch)\n\n### SSCE — Minimal reproducer\n\n**Server** (`server.py`): A server that accepts SSE connections but closes them before sending a complete response, with a `last-event-id` header to trigger the reconnection path.\n\n```python\n\"\"\"Minimal MCP server that drops SSE streams to trigger infinite reconnect.\"\"\"\nimport asyncio\nfrom starlette.applications import Starlette\nfrom starlette.routing import Route\nfrom starlette.responses import Response\nfrom sse_starlette.sse import EventSourceResponse\nimport uvicorn, json, uuid\n\nsession_id = str(uuid.uuid4())\n\nasync def handle_mcp(request):\n    if request.method == \"POST\":\n        body = await request.json()\n        method = body.get(\"method\")\n\n        if method == \"initialize\":\n            resp = {\n                \"jsonrpc\": \"2.0\",\n                \"id\": body[\"id\"],\n                \"result\": {\n                    \"protocolVersion\": \"2025-06-18\",\n                    \"capabilities\": {\"tools\": {}},\n                    \"serverInfo\": {\"name\": \"drop-server\", \"version\": \"0.1.0\"},\n                },\n            }\n            return Response(\n                json.dumps(resp),\n                media_type=\"application/json\",\n                headers={\"mcp-session-id\": session_id},\n            )\n\n        if method == \"notifications/initialized\":\n            return Response(status_code=202, headers={\"mcp-session-id\": session_id})\n\n        if method == \"tools/call\":\n            # Return SSE that sends a priming event with an ID, then drops\n            async def event_generator():\n                yield {\"event\": \"message\", \"id\": \"evt-1\", \"data\": \"\"}\n                # Close without sending the actual response\n                return\n\n            return EventSourceResponse(\n                event_generator(),\n                headers={\"mcp-session-id\": session_id},\n            )\n\n        return Response(status_code=404)\n\n    if request.method == \"GET\":\n        # GET stream for server-initiated messages — also drop immediately\n        async def get_stream():\n            yield {\"event\": \"message\", \"id\": \"evt-get-1\", \"data\": \"\"}\n            return\n\n        return EventSourceResponse(\n            get_stream(),\n            headers={\"mcp-session-id\": session_id},\n        )\n\n    if request.method == \"DELETE\":\n        return Response(status_code=200)\n\napp = Starlette(routes=[Route(\"/mcp\", handle_mcp, methods=[\"POST\", \"GET\", \"DELETE\"])])\n\nif __name__ == \"__main__\":\n    uvicorn.run(app, host=\"0.0.0.0\", port=9999)\n```\n\n**Client** (`client.py`): Connects and calls a tool, demonstrating the infinite loop.\n\n```python\n\"\"\"Client that demonstrates infinite reconnection loop.\"\"\"\nimport asyncio, logging\nlogging.basicConfig(level=logging.INFO)\n\nfrom mcp import ClientSession\nfrom mcp.client.streamable_http import streamable_http_client\n\nasync def main():\n    async with streamable_http_client(\"http://localhost:9999/mcp\") as (read, write, _):\n        async with ClientSession(read, write) as session:\n            await session.initialize()\n            print(\"Initialized. Calling tool (will hang forever)...\")\n            # This call will trigger _handle_reconnection with attempt=0 reset\n            try:\n                result = await asyncio.wait_for(\n                    session.call_tool(\"any_tool\", {}),\n                    timeout=30,\n                )\n            except asyncio.TimeoutError:\n                print(\"CONFIRMED: call_tool hung for 30s (infinite reconnect loop)\")\n\nasyncio.run(main())\n```\n\n### Steps\n\n1. `pip install mcp[cli] sse-starlette uvicorn`\n2. Run server: `python server.py`\n3. Run client: `python client.py`\n4. Observe: client logs show repeated `\"GET stream disconnected, reconnecting in 1000ms...\"` messages. The `call_tool` never returns. After 30s the `wait_for` timeout fires, confirming the hang.\n\n## Root Cause\n\nIn `streamable_http.py`, `_handle_reconnection` (line 437):\n\n```python\nasync def _handle_reconnection(self, ctx, last_event_id, retry_interval_ms, attempt=0):\n    if attempt >= MAX_RECONNECTION_ATTEMPTS:  # Only 2\n        return\n\n    # ... reconnects, iterates SSE ...\n\n    # Line 494: Stream ended without response — resets attempt to 0!\n    await self._handle_reconnection(ctx, reconnect_last_event_id, reconnect_retry_ms, 0)\n```\n\nWhen the reconnection *succeeds* (HTTP 200) but the stream ends without a complete `JSONRPCResponse`, line 494 recurses with `attempt=0`, restarting the counter. Only the exception path (line 498) increments the counter. A server that accepts connections but drops streams causes infinite recursion at 1-second intervals.\n\n## Expected Behavior\n\nAfter `MAX_RECONNECTION_ATTEMPTS` total reconnection attempts (regardless of whether they succeeded at the HTTP level), the client should give up and propagate an error to the caller.\n\n## Suggested Fix\n\nTrack total attempts across the recursion rather than resetting on successful connect:\n\n```python\n# Line 494: increment instead of reset\nawait self._handle_reconnection(ctx, reconnect_last_event_id, reconnect_retry_ms, attempt + 1)\n```\n\nOr add a separate `max_total_reconnection_attempts` counter that is never reset.\n\n## Impact\n\nIn production, this causes MCP client coroutines to hang forever when a server experiences transient stream drops. The calling application has no way to recover without wrapping every MCP call in `asyncio.wait_for()`. We discovered this when an agentquant research job hung for 5+ hours in a reconnection loop after an MCP server's SSE stream dropped.","author":{"url":"https://github.com/jeffplourde","@type":"Person","name":"jeffplourde"},"datePublished":"2026-04-05T11:29:06Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/2393"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:16128a6c-55ed-e59a-e9c2-5f8b6f272c76
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idCED0:25A204:344A4C:46C0D3:6B00C508
html-safe-noncec056ed449c7e2ac25cfd08cee7b051153257eedf8c45cfa674a6e267b3268a45
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRUQwOjI1QTIwNDozNDRBNEM6NDZDMEQzOjZCMDBDNTA4IiwidmlzaXRvcl9pZCI6IjUxNjAwODg0NDY5NjU5NTc4OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac96954e1819e4ce556fbc03cfa916d3d3cff883595f1eba98b5e2a5380a4ae1fa
hovercard-subject-tagissue:4207294746
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/2393/issue_layout
twitter:imagehttps://opengraph.githubassets.com/db03275a57b237b415df0a349facc8278b5b0b6a037f512e9c6b90ea0716e0d7/modelcontextprotocol/python-sdk/issues/2393
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/db03275a57b237b415df0a349facc8278b5b0b6a037f512e9c6b90ea0716e0d7/modelcontextprotocol/python-sdk/issues/2393
og:image:altBug Description _handle_reconnection() in streamable_http.py resets the attempt counter to 0 on line 494 when a reconnection succeeds but the stream ends without delivering a complete response. Thi...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejeffplourde
hostnamegithub.com
expected-hostnamegithub.com
None93edd3bebc4afb7ce711ee74cb5d2a95927850b082a4d43e212222389cb1c415
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release1fee81a280ea86312b69448e261b418189bfd5b5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/issues/2393#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2393
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2F2393
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2393
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2393
Reloadhttps://github.com/modelcontextprotocol/python-sdk/issues/2393
modelcontextprotocolhttps://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Codehttps://github.com/modelcontextprotocol/python-sdk
Issues308 (308)https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests112 (112)https://github.com/modelcontextprotocol/python-sdk/pulls
Actionshttps://github.com/modelcontextprotocol/python-sdk/actions
Projectshttps://github.com/modelcontextprotocol/python-sdk/projects
Security and quality12 (12)https://github.com/modelcontextprotocol/python-sdk/security
Insightshttps://github.com/modelcontextprotocol/python-sdk/insights
https://github.com/modelcontextprotocol/python-sdk
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2393
New issuehttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2393
#2395https://github.com/modelcontextprotocol/python-sdk/pull/2395
jstar0/python-sdk#1https://github.com/jstar0/python-sdk/pull/1
StreamableHTTP client: _handle_reconnection resets attempt counter to 0, causing infinite retry loophttps://github.com/modelcontextprotocol/python-sdk/issues/2393#top
#2395https://github.com/modelcontextprotocol/python-sdk/pull/2395
jstar0/python-sdk#1https://github.com/jstar0/python-sdk/pull/1
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com/jeffplourde
jeffplourdehttps://github.com/jeffplourde
on Apr 5, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#issue-4207294746
Dharit13https://github.com/Dharit13
on Apr 5, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#event-24209003194
Fix infinite reconnection loop in StreamableHTTP clienthttps://github.com/Dharit13/python-sdk/commit/d71da1d1045ff6cf51cef57862376116504bec10
d71da1dhttps://github.com/Dharit13/python-sdk/commit/d71da1d1045ff6cf51cef57862376116504bec10
Fix infinite reconnection loop in StreamableHTTP clienthttps://github.com/Dharit13/python-sdk/commit/98c9b5f1fd65b7538257d6bf460de600c25eae3c
98c9b5fhttps://github.com/Dharit13/python-sdk/commit/98c9b5f1fd65b7538257d6bf460de600c25eae3c
Fix infinite reconnection loop in StreamableHTTP clienthttps://github.com/Dharit13/python-sdk/commit/35eff18cf4bbcd063dfc08de7c7a06404b0cd46b
35eff18https://github.com/Dharit13/python-sdk/commit/35eff18cf4bbcd063dfc08de7c7a06404b0cd46b
Christian-Sidakhttps://github.com/Christian-Sidak
on Apr 6, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#event-24214084237
Fix infinite retry loop in StreamableHTTP _handle_reconnectionhttps://github.com/Christian-Sidak/python-sdk/commit/2efbb423fde7d4377e8a315178589e03b18f738c
https://docs.github.com/articles/closing-issues-via-commit-messages
2efbb42https://github.com/Christian-Sidak/python-sdk/commit/2efbb423fde7d4377e8a315178589e03b18f738c
manjunathgujjarhttps://github.com/manjunathgujjar
on Apr 10, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#event-24384629231
fix: increment reconnection attempt counter on clean stream disconnecthttps://github.com/manjunathgujjar/python-sdk/commit/22552182734c18aa5d10897d73e8272011466430
https://docs.github.com/articles/closing-issues-via-commit-messages
2255218https://github.com/manjunathgujjar/python-sdk/commit/22552182734c18aa5d10897d73e8272011466430
https://github.com/vishal-vanam
vishal-vanamhttps://github.com/vishal-vanam
on Apr 13, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#issuecomment-4237615455
https://github.com/ansSanthoshM
ansSanthoshMhttps://github.com/ansSanthoshM
on Apr 24, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#issuecomment-4311923537
maxisbeyhttps://github.com/maxisbey
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
on Aug 14, 2026https://github.com/modelcontextprotocol/python-sdk/issues/2393#event-29453839443
Sign up for freehttps://github.com/signup?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2393
Sign in to commenthttps://github.com/login?return_to=https://github.com/modelcontextprotocol/python-sdk/issues/2393
P2Moderate issues affecting some users, edge cases, potentially valuable featurehttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22P2%22
bugSomething isn't workinghttps://github.com/modelcontextprotocol/python-sdk/issues?q=state%3Aopen%20label%3A%22bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.