Skip to content

stream: fix unhandled rejection for errored pipeTo writes#64580

Open
dushyant-hada-90 wants to merge 1 commit into
nodejs:mainfrom
dushyant-hada-90:fix-pipeto-unhandled-rejection
Open

stream: fix unhandled rejection for errored pipeTo writes#64580
dushyant-hada-90 wants to merge 1 commit into
nodejs:mainfrom
dushyant-hada-90:fix-pipeto-unhandled-rejection

Conversation

@dushyant-hada-90

@dushyant-hada-90 dushyant-hada-90 commented Jul 18, 2026

Copy link
Copy Markdown

Fixes a v26.4.0 regression where ReadableStream.pipeTo() could crash the
process with an unhandled rejection even when the pipeTo() promise
rejection was already caught.

In #63572, per-chunk setPromiseHandled() was replaced with
markPromiseAsHandled(). That is safe for pending write promises, but when
a later chunk is written after the destination has already errored,
writableStreamDefaultWriterWrite() returns an already-rejected promise.
Marking that promise handled afterwards does not cancel V8's pending
unhandled-rejection notification.

This keeps markPromiseAsHandled() on the writable fast path and falls
back to setPromiseHandled() when the destination is no longer writable
(or close is queued/in flight).

No documentation changes; behavior is restored to match Node.js ≤ v26.3.1,
Deno, Bun, and browsers.

Checklist
  • make -j4 test (UNIX) or vcbuild test (Windows) passes / CI will validate
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Fixes: #64561
Refs: #63572

markPromiseAsHandled does not cancel V8's unhandled-rejection
notification when the write promise is already rejected. Fall back
to setPromiseHandled when the destination is no longer writable.

Fixes: nodejs#64561
Refs: nodejs#63572
Signed-off-by: dushyant <dushyanthada90@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TransformStream error during pipeTo crashes the process despite being caught (v26.4.0 regression)

2 participants