Title: fix(client): propagate SSE POST errors to caller instead of hanging (#2110) by fede-kamel · Pull Request #2483 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: fix(client): propagate SSE POST errors to caller instead of hanging (#2110) by fede-kamel · Pull Request #2483 · modelcontextprotocol/python-sdk
X Title: fix(client): propagate SSE POST errors to caller instead of hanging (#2110) by fede-kamel · Pull Request #2483 · modelcontextprotocol/python-sdk
Description: Summary Fixes the remaining client-side hang from #2110, in sse_client. _send_message (the message-POST coroutine) called response.raise_for_status() with no handler. On a non-2xx (401/403/404/5xx) or a network error, the exception propagated into the post_writer task group and was swallowed by its except Exception: logger.exception("Error in post_writer"). The failure never reached the read stream, so a caller blocked on read_stream.receive() — e.g. ClientSession.initialize() — hung forever. The fix catches httpx.HTTPError inside _send_message and forwards it to read_stream_writer, the pattern stdio.py and websocket.py already use, and that streamable_http.py uses for its >= 400 responses. The caller now receives the error promptly. Scope note This PR was originally broader. Since it was opened, main independently landed the equivalent fix for streamable_http_client (the status_code >= 400 branch in _handle_post_request now sends a JSONRPCError to the read stream with data={"http_status": ...}). That half is therefore dropped here — this is rebased on current main and scoped to the one remaining swallow path: sse_client. It's also distinct from #2340, which addresses the sse_reader/connection path rather than the message-POST path. Verification New regression test test_sse_client_post_error_propagates_to_caller: drives a real SSE handshake whose message POST returns 503 and asserts the caller receives the HTTPStatusError via the read stream within a bounded timeout. Negative control: the test times out (fails) against the unpatched client, and passes with the fix — confirming it reproduces the hang. ./scripts/test: full suite green, 100.00% coverage (branch), strict-no-cover clean. ruff format / ruff check / pyright: clean. Closes #2110.
Open Graph Description: Summary Fixes the remaining client-side hang from #2110, in sse_client. _send_message (the message-POST coroutine) called response.raise_for_status() with no handler. On a non-2xx (401/403/404/5xx)...
X Description: Summary Fixes the remaining client-side hang from #2110, in sse_client. _send_message (the message-POST coroutine) called response.raise_for_status() with no handler. On a non-2xx (401/403/404/5xx)...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2483
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a1f8464b-3d71-c257-d75f-a10f4917fc5c |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A696:1C0DF3:8B89085:BDCBBB1:6A5E8323 |
| html-safe-nonce | fcd2f0854f5e033735e9b6cc1b75ba4e84bca767ac9e8e60f6baa8964fea88f7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjk2OjFDMERGMzo4Qjg5MDg1OkJEQ0JCQjE6NkE1RTgzMjMiLCJ2aXNpdG9yX2lkIjoiNDgyMTY5NzM3NTM4Njg5NTEzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 794ae62cf2153cd1a21e801a9e249265d7f2e8e2f6a672db114de1cf66822729 |
| hovercard-subject-tag | pull_request:3556860197 |
| 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/2483/files |
| twitter:image | https://avatars.githubusercontent.com/u/209537060?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/209537060?s=400&v=4 |
| og:image:alt | Summary Fixes the remaining client-side hang from #2110, in sse_client. _send_message (the message-POST coroutine) called response.raise_for_status() with no handler. On a non-2xx (401/403/404/5xx)... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e0c30ec4bc4cc128be7eee7ef869507723a2ac9916267b7e0d370b3580a5e7ba |
| 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 | 68ef39d284f7f48d37e751bc9bc0a9a4166228d5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width