Repository navigation
fix(client): do not wait for the end of an unread POST reply body #3082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
claude
wants to merge
4
commits into
main
Choose a base branch
from
fix/client-release-post-reply-body
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
945773a
fix(client): do not wait for the end of an unread POST reply body
felixweinberger d02a991
Merge branch 'main' into fix/client-release-post-reply-body
felixweinberger c140325
fix(client): let an unread POST reply end before releasing it
felixweinberger 4db666d
Merge branch 'main' into fix/client-release-post-reply-body
felixweinberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@modelcontextprotocol/client': patch | ||
| --- | ||
|
|
||
| `StreamableHTTPClientTransport.send()` and `SSEClientTransport.send()` no longer wait for the end of a POST reply with a 2xx status whose body they do not read (a `202`, a reply to a message with no requests, a reply with an unexpected content type). A server or proxy that sends the headers of such a reply and keeps it open no longer stalls `send()` or `Client.connect()`. The unread body is still read to its end, but `send()` does not wait for that; a body that has not ended after 100 ms is cancelled, which closes its HTTP/1.1 connection unless a custom `fetch` holds a clone of the reply. A body with no `getReader()`, as a custom `fetch` may return, is read in the same way but never cancelled. POST replies with any other status and `terminateSession()` still wait for the end of the body. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟣 pre-existing, not blocking: pre-existing: A server or proxy that holds a reply open still stalls
terminateSession()and anysend()answered with a 401, exactly as on the base branch. Only the four 2xx POST drains were converted. Other drains whose text is thrown away still runawait response.text?.(). Fix: release every discarded reply body without awaiting, for example withreleaseBody(response), which covers the 5 sites listed. Same pattern at 5 sites (streamableHttp.ts:1095, streamableHttp.ts:1099, streamableHttp.ts:1266, sse.ts:472, sse.ts:476). The description leaves these out on purpose, but the DELETE reply is as unread as a 202.A small fix can ride a push you are already making; otherwise a short reply is enough.
Why this was flagged
Trigger (peer behaviour, not reproducible from this checkout): the peer the changeset names, one that sends headers and keeps the response open, answers a DELETE with 200 or a POST with 401 while an
authProvideris set.terminateSession()at packages/client/src/client/streamableHttp.ts:1266 runsawait response.text?.().catch(() => {})before it reads the status, so it never settles._send()awaits the same discarded drain at :1095 (afteronUnauthorized, before the retry) and :1099 (before throwingUnauthorizedError), and packages/client/src/client/sse.ts:472 and :476 do the same, sosend()and aClient.connect()whose first POST is challenged still hang. The base branch behaves identically; the diff changes only :1168, :1212, :1219 and sse.ts:495. No timeout guards these awaits; onlytransport.close()aborting_abortControllerends them. The drains at :1111 and sse.ts:488 use the text and are not part of this.Verification: pre-existing — triggers when a server or proxy sends headers and holds the response open on a DELETE reply, or on a 401 POST reply while an
authProvideris set. packages/client/src/client/streamableHttp.ts:1265-1266 —terminateSession()runsawait response.text?.().catch(() => {});before the status check at :1270. None of the lines above appear in the diff, so the base fails the same way by the same route.Finding ID:
f-a05dae63