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:7f92c1b7-ebb1-aeb4-2d00-3643af6376c0 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C1C0:4AA5E:3F99BA:53E9C1:6A5B526C |
| html-safe-nonce | 3e8014dcbef2c5799d4df9de198dfa66bc9cdad2361d091bddbeb9828d471e69 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMUMwOjRBQTVFOjNGOTlCQTo1M0U5QzE6NkE1QjUyNkMiLCJ2aXNpdG9yX2lkIjoiNTIxNzYxOTE0NjIxNzQzNzI0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 59b5fb5a9e3a3ef7204d9c648d258ed67018498aa75ab3e40146dc2bca471435 |
| 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