Title: fix(client): avoid stack growth during SSE reconnection by namtran1812 · Pull Request #3790 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(client): avoid stack growth during SSE reconnection by namtran1812 · Pull Request #3790 · modelcontextprotocol/python-sdk
X Title: fix(client): avoid stack growth during SSE reconnection by namtran1812 · Pull Request #3790 · modelcontextprotocol/python-sdk
Description: Fixes #3791 Summary Long-lived requests can fail after repeated productive SSE reconnects because _handle_reconnection() recursively awaits itself, accumulating Python stack frames. In a deterministic reproduction, each connection delivers a notification with a new event ID before closing. At the default recursion limit, the client fails after approximately 970 connections with CONNECTION_CLOSED and “reconnection attempts were exhausted,” before the final response arrives. Raising the recursion limit allows the same scenario to complete all 1,500 connections. Replace recursive reconnection with an iterative loop so productive resumptions can continue without accumulating stack frames. Changes Replace recursive calls with a loop carrying the current event ID, retry delay, and attempt count. Exit each response context before opening the next connection. Preserve existing retry accounting, resumption-token callbacks, cancellation, and terminal error handling. Add a regression covering 1,500 connections, ordered delivery of 1,499 notifications, resumption cursors, and the final response without modifying Python’s recursion limit. This addresses stack growth separately from the no-progress retry-budget behavior tracked in #2393 and proposed in #2395. Validation Confirmed the new regression fails on unmodified code and passes with this change. macOS / Python 3.13: all 120 transport tests passed. Linux / Python 3.12: full suite passed—6,227 passed, 8 skipped, 1 xfailed. Coverage: 100%, with strict-no-cover passing. Ruff lint, formatting, Pyright, and git diff --check passed. The reproduction uses a synthetic HTTP peer; this failure has not been verified in a production deployment. AI assistance AI assistance was used for investigation, implementation, and validation. I reproduced the failure and ran the transport tests, lint, formatting, and type checks locally.
Open Graph Description: Fixes #3791 Summary Long-lived requests can fail after repeated productive SSE reconnects because _handle_reconnection() recursively awaits itself, accumulating Python stack frames. In a determinis...
X Description: Fixes #3791 Summary Long-lived requests can fail after repeated productive SSE reconnects because _handle_reconnection() recursively awaits itself, accumulating Python stack frames. In a determinis...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/3790
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:1274dfb3-6d0a-ddcd-9def-e827b5087880 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8648:76F02:9BEC2E:CA77AA:6B00E3B9 |
| html-safe-nonce | 1c37ce188b69154f42e869fe7147bf91a6de81e47bcc66ee3b1ca07b5fd5f476 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NjQ4Ojc2RjAyOjlCRUMyRTpDQTc3QUE6NkIwMEUzQjkiLCJ2aXNpdG9yX2lkIjoiMzU4ODk0MDExNjc0OTUwOTU2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e732e4fa8acaecddf28542c4e40accf63ec537e56d96a1f853bc6b711d8c3250 |
| hovercard-subject-tag | pull_request:5099729179 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/3790/files |
| twitter:image | https://avatars.githubusercontent.com/u/158846154?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/158846154?s=400&v=4 |
| og:image:alt | Fixes #3791 Summary Long-lived requests can fail after repeated productive SSE reconnects because _handle_reconnection() recursively awaits itself, accumulating Python stack frames. In a determinis... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width