Skip to content

Support web streams in stream.pipeline() - #7338

Merged
jasnell merged 7 commits into
mainfrom
jasnell/node-streams-02-pipeline
Sep 15, 2026
Merged

jasnell merged 7 commits into
mainfrom
jasnell/node-streams-02-pipeline

Conversation

@jasnell

@jasnell jasnell commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Next in a new stack of streams fixes and tests.

@jasnell
jasnell added this pull request to stack #7337 September 12, 2026 23:52
@jasnell
jasnell requested review from a team as code owners September 12, 2026 23:52
Comment thread src/node/internal/streams_pipeline.js Resolved
@ask-bonk

ask-bonk Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

Adds Web Streams support to node:stream pipeline APIs.

  1. [P1] Web sources preceding function stages can hang on abort or downstream failure (src/node/internal/streams_pipeline.js:425). Posted an inline suggestion.

github run

@jasnell
jasnell requested review from guybedford and npaun September 13, 2026 00:01

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

Compared the shared parts against upstream lib/internal/streams/pipeline.js (Node 22) and they match; traced the readWeb/pumpToWeb error paths (closed vs ready rejection order, cancel-on-closed no-op, releaseLock rejecting closed guarded by released) and found no double-finish or dropped error. Ran the stream suites plus a few extra probes locally (pre-aborted signal on an all-web promises.pipeline, web sink rejecting while the web source is idle, node sink failing behind a TransformStream) — all behave as documented. Two minor notes inline.

Comment thread src/node/internal/streams_pipeline.js Resolved
Comment thread src/node/internal/streams_pipeline.js Resolved
@jasnell
jasnell force-pushed the jasnell/node-streams-02-pipeline branch from 71607b4 to 677a944 Compare September 14, 2026 17:50
Base automatically changed from jasnell/node-streams-01-stream-adapters to main September 15, 2026 02:08
pipelineImpl predated upstream's web-stream stages: a ReadableStream was
accepted as the source only because it is async-iterable, while a
WritableStream or TransformStream anywhere later fell through to
Duplex.from() and threw ERR_INVALID_ARG_TYPE. Port the current upstream
pipelineImpl, pumpToNode/pumpToWeb, and pipe(): a web readable or a
TransformStream's readable is consumed through async iteration, a web
writable or a TransformStream's writable is fed through a writer that
honors ready, closes at the end (unless end is false), and aborts on
failure. The port also brings upstream's finishOnlyHandleError for
errors after a stage completed, ends the destination only when the
source has not already finished, and no longer awaits a destination it
was told not to end. stream/promises pipeline() now recognises a
trailing web stream as a destination rather than the options bag.

The legacy (unflagged) cell pins that pipeline() keeps working over
runtime-provided web streams and that, without
transformstream_enable_standard_constructor, a TransformStream stage is
an identity transform that ignores its transformer.

The module lints clean, so its blanket eslint-disable directive goes.
pumpToNode and pumpToWeb consumed a web ReadableStream source through the
stream's own async iterator, which nothing in the pipeline could reach: a
signal abort or a failing node destination while the source was idle left
the iterator's pending read hanging, and with it the pipeline — every
stage but the source was destroyed, the callback never fired. The iterator
also awaited a promise-valued chunk before handing it on, so an objectMode
destination received the settled value instead of the promise that was
enqueued.

The web source is now read through a reader the pump owns, registered with
the pipeline's teardown: destroying the pipeline cancels the reader with
the pipeline's error (a source the pump never started reading is cancelled
directly), which settles the pending read and fails the iteration with that
error; leaving the loop early cancels the stream as the stream's iterator
would. Chunks pass through as they are. The pump feeding a web destination
registers its writer the same way, so the teardown aborts the destination
with the pipeline's error and wakes a pump waiting on writer.ready; a pump
that has completed is left alone (with end: false its writer stays open).
The pump feeding a web WritableStream learned of the destination's failure
only from its next write: a sink whose controller errored, or that rejected
a write, while the source was idle left a pipeline pending until the source
produced again — forever, for a source waiting on something else. eos()
reports a node destination's failure on its own; watch the writer's closed
promise the same way and report the rejection to the pipeline at once,
which tears its stages down (failing this pump's read) and fires the
callback with the sink's error. A pump that has already finished ignores
the rejection: its own completion reported first.
pumpToWeb acquired the destination's writer inside the async pump, so a
WritableStream that was already locked made getWriter() throw into the
pump's promise, where the rejection went unobserved: the pipeline never
completed and its callback never fired, in the callback and the
stream/promises forms alike. Catch the lock error and report it through
finish once the pipeline has wired its stages, as a failed write would be:
the pipeline fails with the lock error, the source is destroyed, and the
existing writer keeps its lock.
…ine()

A web source yielding a chunk the node destination cannot take (a view
over a detached ArrayBuffer) fails the pipeline with the conversion's
TypeError — through the callback and as the destination's error — and the
source is cancelled by the pump's iteration leaving early, without a
reason, as in Node. A promises pipeline aborted while its read on a web
source is pending rejects once with the AbortError, cancels the source
with it (settling the pending read) and releases its lock, and destroys
the destination with it.
The pump reading a web ReadableStream learned of the stream's failure only
from its next read. Waiting on a node destination's backpressure it made
none, so a destination that never drained left a pipeline whose source had
already errored pending forever. Watch the reader's closed promise, as the
web-destination pump watches its writer's, and report the failure to the
pipeline at once: every stage is destroyed with it and the callback fires.
@jasnell
jasnell force-pushed the jasnell/node-streams-02-pipeline branch from 677a944 to 32f84d2 Compare September 15, 2026 02:08
@jasnell
jasnell merged commit 4bad72c into main Sep 15, 2026
34 of 36 checks passed
@jasnell
jasnell deleted the jasnell/node-streams-02-pipeline branch September 15, 2026 13:55
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.

2 participants