Title: Fix stdio_client BrokenResourceError race condition during shutdown by weiguangli-io · Pull Request #2268 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Fix stdio_client BrokenResourceError race condition during shutdown by weiguangli-io · Pull Request #2268 · modelcontextprotocol/python-sdk
X Title: Fix stdio_client BrokenResourceError race condition during shutdown by weiguangli-io · Pull Request #2268 · modelcontextprotocol/python-sdk
Description: Summary Fixes #1960. Supersedes #2219 (which was closed). During stdio_client shutdown, the finally block closes read_stream (the receiving end of a zero-buffer memory channel) while stdout_reader may still be blocked on send(). When the receiving end closes underneath a pending send(), anyio raises BrokenResourceError — not ClosedResourceError. The existing except clause only caught ClosedResourceError, so BrokenResourceError escaped into an ExceptionGroup. The fix catches BrokenResourceError alongside ClosedResourceError in both stdout_reader and stdin_writer. This is the minimal, correct change: ClosedResourceError means "you called send on a handle you already closed", while BrokenResourceError means "the other end was closed" — both are expected during shutdown and should be handled identically. Test plan Added regression test test_stdio_client_no_broken_resource_error_on_shutdown that reproduces the exact scenario: server sends a JSON-RPC message, client exits without consuming the read stream All 12 existing tests/client/test_stdio.py tests pass
Open Graph Description: Summary Fixes #1960. Supersedes #2219 (which was closed). During stdio_client shutdown, the finally block closes read_stream (the receiving end of a zero-buffer memory channel) while stdout_reader ...
X Description: Summary Fixes #1960. Supersedes #2219 (which was closed). During stdio_client shutdown, the finally block closes read_stream (the receiving end of a zero-buffer memory channel) while stdout_reader ...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2268
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0bc791c2-69a4-e39c-a831-84e38fc0dae5 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CD4E:1903FC:2B3D7F:392EFA:6A5B83EB |
| html-safe-nonce | 612050157e0e1dacdf75d2ed219a185e8d7855deec4f650ab3b74ccd562aa639 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRDRFOjE5MDNGQzoyQjNEN0Y6MzkyRUZBOjZBNUI4M0VCIiwidmlzaXRvcl9pZCI6IjY0Mjc5NjkxOTIyMzU1OTg4MjciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7685229b197a0124f6a9d6ee969a4745ea62737062246444897d979f58a288eb |
| hovercard-subject-tag | pull_request:3381763286 |
| 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/2268/files |
| twitter:image | https://avatars.githubusercontent.com/u/61958072?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/61958072?s=400&v=4 |
| og:image:alt | Summary Fixes #1960. Supersedes #2219 (which was closed). During stdio_client shutdown, the finally block closes read_stream (the receiving end of a zero-buffer memory channel) while stdout_reader ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width