Skip to content

fix(cache): settle Cache.add/addAll for responses with a body - #5658

Closed
edenbuilds wants to merge 1 commit into
nodejs:mainfrom
edenbuilds:fix/cache-add-body-hang
Closed

edenbuilds wants to merge 1 commit into
nodejs:mainfrom
edenbuilds:fix/cache-add-body-hang

Conversation

@edenbuilds

Copy link
Copy Markdown
Contributor

Summary

  • Cache.add / Cache.addAll hung forever when the response had a body (204/no-body settled fine).
  • Root cause: fetchFinale attaches stream.finished() for end-of-body, but undici body streams are pull-driven — with no consumer, the stream never finishes and processResponseEndOfBody never resolves the waiters (issue Cache.add() and Cache.addAll() never settle for a response with a body #5615).
  • Fix mirrors Cache.put: clone the response, fully read the original stream (unlocks end-of-body), set body.source on the clone for storage.

Test plan

Made with Cursor

Pull-driven body streams were never consumed, so processResponseEndOfBody
never ran and Cache.add hung forever. Clone, fully read (as Cache.put does),
and store body.source. Fixes nodejs#5615.

Co-authored-by: Cursor <cursoragent@cursor.com>
@metcoder95
metcoder95 requested a review from KhafraDev August 6, 2026 08:22

@KhafraDev KhafraDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If, as the issue OP suggested, it is caused by #3093, then the fix is to revert that, not some crummy ai slop.

@edenbuilds

Copy link
Copy Markdown
Contributor Author

Thanks, I checked this against current main and reproduced the tradeoff. I refreshed a local copy onto current main (the fork branch was 96 commits behind): restoring the #3093 transform-stream path by itself still leaves the new body-bearing cache.add() regression pending, while retaining the current cache workaround makes the subsequent cache.match() fail because the stored response stream is locked. I have not pushed a speculative revert that would leave either path broken. The remaining fix needs a targeted cache/fetch integration shape, or confirmation that you want the broader #3093 revert despite that regression.

@KhafraDev KhafraDev closed this Sep 21, 2026
@KhafraDev

Copy link
Copy Markdown
Member

#5844 is an actual fix. Please don't send another ai generated response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants