Uh oh!
There was an error while loading. Please reload this page.
fix(client): replace body.cancel() with text() to prevent hanging - #1320
Conversation
|
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
358910dComparemattzcarey
commented
Dec 19, 2025
Tests are failing here, reckon you could have a look |
commit: |
grimmerk
commented
Dec 19, 2025
@mattzcarey thanks for the reminder. I've force-pushed it to fix the broken tests. |
grimmerk
commented
Jan 9, 2026
Hi! Happy new year 🎉 Just checking in — is there anything else needed from my side to get this merged? Happy to help if so. |
Uh oh!
There was an error while loading. Please reload this page.
…delcontextprotocol#1320) Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
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: