-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(client): replace body.cancel() with text() to prevent hanging #1320
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
base: main
Are you sure you want to change the base?
fix(client): replace body.cancel() with text() to prevent hanging #1320
Conversation
|
mattzcarey
left a comment
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.
LGTM
body.cancel() can hang indefinitely with certain server responses
(e.g., Sentry MCP's OAuth flow). Using text?.().catch(() => {}) is safer:
- Always completes (reads all data)
- Releases connection (body consumed)
- No stream coordination needed
- Uses optional chaining for compatibility with mock responses
Fixes regression from modelcontextprotocol#1173 and modelcontextprotocol#1214.
c131704 to
358910d
Compare
|
Tests are failing here, reckon you could have a look |
commit: |
|
@mattzcarey thanks for the reminder. I've force-pushed it to fix the broken tests. |
Replace
response.body.cancel()withresponse.text().catch(() => {})in client package to prevent indefinite hanging with certain server responses.Motivation and Context
PRs #1173 and #1214 added
body.cancel()calls to fix connection leaks in Cloudflare Workers. However,body.cancel()can hang indefinitely with certain MCP servers (e.g., Sentry MCP during OAuth metadata discovery).The hang occurs because
cancel()attempts to abort the stream, which requires coordination with the server that doesn't always complete.Using
text().catch(() => {})instead:In all affected code paths (OAuth metadata discovery, error responses, 202 Accepted, session termination), the response bodies are small, making
text()a safe and efficient choice.This preserves the original fix for Cloudflare Workers connection leaks while eliminating the hanging issue.
How Has This Been Tested?
https://mcp.sentry.dev/mcp) which previously hung indefinitelyBreaking Changes
None. Drop-in replacement that maintains the same behavior.
Types of changes
Checklist
Additional context
Fixes regression introduced in #1173 and #1214.
References: