fix(deduplicate): detach the primary on abort instead of rejecting the group - #5765
fix(deduplicate): detach the primary on abort instead of rejecting the group#5765pacocartones wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5765 +/- ##
==========================================
+ Coverage 93.50% 93.53% +0.02%
==========================================
Files 110 110
Lines 39072 39439 +367
==========================================
+ Hits 36534 36888 +354
- Misses 2538 2551 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
| acWaiter.abort() | ||
| strictEqual((await waiterOutcome)?.name, 'AbortError') | ||
|
|
||
| await sleep(50) |
There was a problem hiding this comment.
Please do not use sleep, it's flaky.
| const primaryOutcome = primary.then(() => 'resolved', err => err) | ||
| const waiterOutcome = waiter.then(() => 'resolved', err => err) | ||
|
|
||
| await sleep(50) |
There was a problem hiding this comment.
Please do not use sleep, it's flaky.
| const primaryOutcome = primary.then(() => 'resolved', err => err) | ||
|
|
||
| // Let the waiter join the coalesced group, then abort the primary. | ||
| await sleep(50) |
There was a problem hiding this comment.
Please do not use sleep, it's flaky.
| requestsToOrigin++ | ||
| // Hold the response open long enough for the primary to abort while the | ||
| // waiter is still attached. | ||
| await sleep(300) |
There was a problem hiding this comment.
Please do not use sleep, it's flaky.
…e group Aborting the first request of a coalesced group cancelled the shared dispatch, so every other caller waiting on it — including callers that passed no signal — was rejected with an AbortError. Coalescing was not transparent: whether your request succeeded depended on who asked first and whether they had a timeout. Hand the primary a proxied controller (same shape as the waiting handlers). Aborting it now settles only the primary and detaches it from the group; the underlying request is cancelled only once no member — primary or waiting handler — is left waiting. This also releases the pendingRequests entry when every member of a group aborts, so a later request never joins a group with no consumers left. With no waiters the abort still propagates exactly as before. Refs: nodejs#5711 Signed-off-by: Paco Cartones <pacocartones@users.noreply.github.com>
094431e to
06dcbf1
Compare
|
The sleep-based waits from the earlier revision have been removed from the current head, and the full CI matrix is green. @mcollina, could you please take another look when convenient? |
Fixes #5711.
Problem
With
interceptors.deduplicate(), aborting the primary request of a coalesced group rejected every waiter withAbortError— even waiters that passed nosignal. The primary received the real dispatch controller, so its abort tore down the shared dispatch and rejected all members.Fix
The primary now receives a proxied controller (mirroring the existing
#createWaitingHandler). Aborting it detaches only the primary and defers to#maybeAbortRealDispatch, which tears down the shared dispatch only once no member (primary or waiter) is left waiting, releasing thependingRequestsentry viaonComplete. Pause/resume still forward to the real controller, so backpressure is unchanged. With no waiters, abort propagates exactly as before.Test
test/interceptors/deduplicate.js:deduplicate 38/38 + cache 88/88 + retry 16/16,
npm run lint— all green.