fix(mock): guard aborted requests in async reply callback rejection - #5764
Open
pacocartones wants to merge 1 commit into
Open
fix(mock): guard aborted requests in async reply callback rejection#5764pacocartones wants to merge 1 commit into
pacocartones wants to merge 1 commit into
Conversation
When a reply options callback returns a promise, the request can be aborted while that promise is still pending. controller.abort() then settles the request through onResponseError. If the callback promise later rejects, the rejection arm called handler.onResponseError(null, err) again, double-settling an already-aborted request. Add the same `if (aborted) return` guard that handleReply() already uses so the late rejection is dropped once the request has been aborted. Signed-off-by: Paco Cartones <pacocartones@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5764 +/- ##
==========================================
+ Coverage 93.50% 93.52% +0.01%
==========================================
Files 110 110
Lines 39072 39080 +8
==========================================
+ Hits 36534 36549 +15
+ Misses 2538 2531 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
The only non-green checks are two cancelled CI jobs (Node.js 24 Ubuntu coverage and Node.js 22 Ubuntu). I tried the Actions rerun endpoint, but contributors receive HTTP 403. Could a maintainer rerun the cancelled jobs when convenient? |
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.
Problem
In
lib/mock/mock-utils.js,sendReply()handles an async reply options callback (the.reply(() => ...)/response.callbackpath from #5534). Its resolve arm goes throughhandleReply()(guarded byif (aborted) return), but the reject arm calledhandler.onResponseError(null, err)with no abort guard.When a request with a body is aborted while that options-callback promise is still pending,
controller.abort()already settles the request viaonResponseError(first terminal). The callback promise then rejects and callsonResponseErroragain → a double-settle of an already-aborted request.This is distinct from #5762: that one guards the data/body function promise in
handleReply(); this guards the reply options callback promise insendReply()— different function, different call site, different feature.Fix
Guard the reject arm with
if (aborted) return, mirroring the guardhandleReply()already applies.Test
test/mock-delayed-abort.js: aCountingHandlercountsonResponseError; a POST with a body and an options callback that rejects at 50ms, aborted at 10ms, assertsonResponseErrorfires exactly once.2 !== 1(double-settle).node --test test/mock-delayed-abort.js(4 pass), whole mock suite via borp (340 pass),npm run lint— all green.