Repository navigation
Support web streams in stream.pipeline() - #7338
Merged
Merged
Conversation
Contributor
|
I'm Bonk, and I've done a quick review of your PR. Adds Web Streams support to
|
guybedford
approved these changes
Sep 14, 2026
guybedford
left a comment
Member
There was a problem hiding this comment.
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.
jasnell
force-pushed
the
jasnell/node-streams-02-pipeline
branch
from
September 14, 2026 17:50
71607b4 to
677a944
Compare
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
force-pushed
the
jasnell/node-streams-02-pipeline
branch
from
September 15, 2026 02:08
677a944 to
32f84d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Next in a new stack of streams fixes and tests.