Skip to content

fix(cache): Cache.add() and Cache.addAll() hang for responses with bodies - #5627

Open
marko1olo wants to merge 1 commit into
nodejs:mainfrom
marko1olo:fix/cache-add-body
Open

fix(cache): Cache.add() and Cache.addAll() hang for responses with bodies#5627
marko1olo wants to merge 1 commit into
nodejs:mainfrom
marko1olo:fix/cache-add-body

Conversation

@marko1olo

Copy link
Copy Markdown
Contributor

Problem

Cache.add() and Cache.addAll() deadlock when the response has a body: the spec requires the implementation to read the response body before storing it, but the current code never drains the original stream, so the promise never settles.

Fix

Clone the response before storing (so the original body can be consumed independently), and explicitly drain the original stream after the clone is created.

Tests

Added test/cache/cache-add-body.js — all pass (node --test test/cache/cache-add-body.js).

Split from #5626 as requested by @mcollina.

@codecov-commenter

codecov-commenter commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.86%. Comparing base (2ab178a) to head (13ef5fd).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/web/cache/cache.js 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5627      +/-   ##
==========================================
+ Coverage   93.50%   93.86%   +0.35%     
==========================================
  Files         110      110              
  Lines       38455    38484      +29     
==========================================
+ Hits        35959    36122     +163     
+ Misses       2496     2362     -134     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollina
mcollina requested a review from KhafraDev August 1, 2026 08:00
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