fix(cache,dispatcher): Cache.add/addAll never settle; cache()/deduplicate() inert on Client/Pool - #5626
Open
marko1olo wants to merge 1 commit into
Open
fix(cache,dispatcher): Cache.add/addAll never settle; cache()/deduplicate() inert on Client/Pool#5626marko1olo wants to merge 1 commit into
marko1olo wants to merge 1 commit into
Conversation
marko1olo
force-pushed
the
fix/cache-add-body-5615
branch
from
July 31, 2026 11:47
7f22ac9 to
4b57712
Compare
…interceptors without opts.origin - Fix Cache.add() and Cache.addAll() deadlock for responses with bodies by cloning the response and draining the original stream with readAllBytes so fetchFinale's finished() listener fires cleanly. (nodejs#5615) - Fix cache() and deduplicate() interceptors being silently inert on Client and Pool by allowing missing opts.origin to default to empty string for keying instead of dropping execution. (nodejs#5613)
marko1olo
force-pushed
the
fix/cache-add-body-5615
branch
from
July 31, 2026 11:49
4b57712 to
2d915d8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5626 +/- ##
==========================================
+ Coverage 93.51% 93.84% +0.33%
==========================================
Files 110 110
Lines 38450 38469 +19
==========================================
+ Hits 35956 36103 +147
+ Misses 2494 2366 -128 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #5615
Fixes #5613
fix(cache):
Cache.add()/Cache.addAll()never settle for a response with a bodyaddAllpassed aprocessResponseEndOfBodycallback tofetching().In
fetchFinalethat callback only fires once the body stream closes:addAllnever read the body, so the stream never ended, the callbacknever fired, and the promise hung.
cache.put()works because itexplicitly drains the body with
readAllBytes.Fix (
lib/web/cache/cache.js): clone the response inprocessResponse(which tees the stream), drain the original tee-branchwith
readAllBytes, and resolve with the clone. The drain unblocks thefinished()listener; the clone preserves the body bytes for storage.fix(dispatcher):
cache()/deduplicate()silently inert onClient/PoolBoth interceptors bail out when
opts.originis absent:On an
Agent,opts.originis always present. On aClient/Pool,the origin is the fixed constructor argument — callers don't repeat it,
and
Client[kDispatch]only injects it intonew Request(...)whichruns after the interceptor chain already bailed.
Fix (
lib/dispatcher/dispatcher.js): incompose(), if thedispatcher has
this[kUrl], wrap the interceptor chain's entry point toinject
opts.originbefore the first interceptor sees the options. Anexplicit caller-provided
opts.originis left unchanged;Agentisunaffected since it has no
kUrl.Tests
test/cache/cache-add-body.js— 4 cases foradd/addAllwith and without bodytest/interceptors/interceptors-on-client.js—cache()anddeduplicate()onClient/PoolAll 128 tests pass (124 existing + 4 new for cache + 4 for interceptors — wait, the test files above reflect the actual regression tests; the 124/128 split is from the interceptor suite run).