fix: resolve request hang with large API responses#437
Merged
angeloashmore merged 6 commits intomasterfrom Feb 10, 2026
Merged
Conversation
Replace `response.clone()` with a memoized response wrapper that caches promises for `text()`, `json()`, and `blob()` reads. This allows multiple callers sharing a deduplicated request to safely read from the same response without stream/body handling issues. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Clone the response before reading text/blob to avoid "body already read" errors when both methods are called on the same memoized response. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
lihbr
approved these changes
Jan 30, 2026
Buffers the response body as a blob immediately instead of using response.clone(). This fixes hanging requests in Node.js 22+ where backpressure blocks the cloned stream when the original is not consumed. See: node-fetch/node-fetch#139 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Replace verbose wrapper with lazy caching variables with a compact implementation that eagerly buffers the blob and derives text/json from it on each call. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mockResolvedValue reuses one Response object across calls, but real fetch always returns a fresh Response. Use mockImplementation so each call creates a new Response, avoiding "Body has already been read". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lihbr
approved these changes
Feb 8, 2026
pageSize and fetchLinks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves: #435
Description
Fixes requests hanging indefinitely in Node.js 22+ when using methods like
getByType(),get(), etc.Root cause: The
request()function deduplicates concurrent GET requests to the same URL, sharing a singleResponseacross callers. It then calledresponse.clone()so each caller could read the body independently. In Node.js 22+, cloned responses share the same underlying stream — if the original response body is never consumed, backpressure blocks the clone from being read, causing.json()to hang forever.Solution: Instead of cloning, buffer the response body as a blob immediately when the response is received, then derive text/JSON from the buffered blob on demand. This eliminates
response.clone()entirely and works for both text (JSON API responses) and binary data (image uploads via WriteClient).Checklist
How to QA
npm test