Skip to content

Propagate fetch body read errors through pipe streams - #1499

Open
Hashim1999164 wants to merge 1 commit into
google:mainfrom
Hashim1999164:fix/fetch-pipe-unhandled-rejection-1443
Open

Propagate fetch body read errors through pipe streams#1499
Hashim1999164 wants to merge 1 commit into
google:mainfrom
Hashim1999164:fix/fetch-pipe-unhandled-rejection-1443

Conversation

@Hashim1999164

@Hashim1999164 Hashim1999164 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

responseToReadable assigned an async _read handler that awaited reader.read() without a try/catch. When the response body failed (network drop, abort, corrupted stream), that became an unhandled promise rejection and could crash the Node process.

This catches read failures and calls rs.destroy(err) so the error flows through the piped stream instead.

Fixes #1443

Test plan

  1. Review the try/catch around reader.read() in src/goods.ts
  2. Manually: start fetch(url, { signal }).pipe\cat``, abort the signal mid-stream, and confirm the pipe rejects without an unhandledRejection

Wrap responseToReadable reader.read() in try/catch and destroy the
Readable with the error so fetch().pipe no longer leaves unhandled
promise rejections when the response stream fails.
Fixes google#1443.
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.

[Bug]: Unhandled promise rejection in fetch().pipe() when response stream errors

1 participant