Skip to content

fix crash on abort when body is not a stream#1852

Open
sbingner wants to merge 1 commit into
node-fetch:mainfrom
sbingner:main
Open

fix crash on abort when body is not a stream#1852
sbingner wants to merge 1 commit into
node-fetch:mainfrom
sbingner:main

Conversation

@sbingner
Copy link
Copy Markdown

Purpose

This causes node-fetch to stop crashing node if you abort a request

Changes

Additional information


  • I updated readme
  • I added unit test(s)

Copy link
Copy Markdown

@rsbasic rsbasic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: APPROVE (bug fix, LOW risk)

Author: @sbingner — established developer (account since 2010, 758 followers).

This fixes a crash that occurs when aborting a request where the body stream object is different from the source body. The current code assumes body === stream and attaches an error handler only to body. When they differ, aborting can trigger an unhandled error on stream.

The fix adds a parallel error handler on stream when stream !== body. The error wrapping logic is identical to the existing handler — converts non-FetchBaseError instances to FetchError with type 'system'. This is defensive programming, not a behavioral change.

Scope check: Only touches src/body.js, adds 9 lines, no imports changed, no dependencies added. The pattern matches the existing error handler 10 lines below it.

Verdict: Safe to merge. Small, defensive fix for a real crash scenario from a credible contributor. Has been open since July 2025 — 8 months waiting for review.

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.

Unhandled 'error' event when using AbortSignal to cancel requests

2 participants