Skip to content

fix(fetch): preserve falsy abort reasons - #6232

Merged
mcollina merged 1 commit into
nodejs:mainfrom
rome-xi:fix/6231-preserve-falsy-abort-reason
Nov 21, 2026
Merged

mcollina merged 1 commit into
nodejs:mainfrom
rome-xi:fix/6231-preserve-falsy-abort-reason

Conversation

@rome-xi

@rome-xi rome-xi commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #6231.

When fetch is aborted with a falsy reason (false, 0, or ''), Fetch.abort treated that value as "not given" (if (!error)) and replaced it with a generic AbortError DOMException. The Fetch Standard abort steps use the supplied error, so the body (and the pending fetch) should reject with that reason.

This changes the fallback to error === undefined only. controller.abort() with no argument still rejects with an AbortError. Truthy custom reasons are unchanged.

Tests

test/fetch/abort.js covers abort while reading the response body (the issue repro) and while the fetch is still waiting for a response:

  • false, 0, and '' reject with a value that is Object.is-equal to signal.reason
  • a custom Error still works
  • omitting the reason still yields an AbortError DOMException

These five body-read cases fail on current main and pass after the change. node --test test/fetch/abort.js: 16 passing. A nearby abort slice (abort.js, abort2.js, and related issue tests): 47 passing, 6 skipped.

Fetch.abort treated any falsy error as "not given" and replaced
false, 0, and '' with a generic AbortError DOMException. Fall back
only when the abort reason is undefined.

Refs: nodejs#6231
Signed-off-by: rome-xi <2685138823@qq.com>

@mcollina mcollina 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.

lgtm

@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.72%. Comparing base (670d0b6) to head (7ef3138).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6232   +/-   ##
=======================================
  Coverage   91.71%   91.72%           
=======================================
  Files         113      113           
  Lines       44813    44813           
=======================================
+ Hits        41102    41103    +1     
+ Misses       3711     3710    -1     

☔ 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 merged commit 5d7f657 into nodejs:main Nov 21, 2026
38 checks passed
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.

Aborted fetch does not throw signal.reason

3 participants