GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: keep async context of pipeTo watchers by mcollina · Pull Request #67052 · nodejs/node

Conversation

@mcollina

@mcollina mcollina commented Oct 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

The ClosedPromiseHook records that pipeTo() and tee() install as the [[closedPromise]] of their reader and writer (#66424) enqueue the watcher from whoever settles the record. As a result, the source-closed, source-errored and dest-errored steps of pipeTo() run in the async context of the code that closed or errored the stream: the destination's close()/abort() and the source's cancel() observe the wrong AsyncLocalStorage store. This is the same class of bug as #66906.

const ts = new TransformStream();
const ws = new WritableStream({ close() { console.log(als.getStore()); } });
als.run('piper', () => ts.readable.pipeTo(ws));
const w = ts.writable.getWriter();
await als.run('closer', () => w.close()); // logs 'closer', v24/v26.5 log 'piper'

This captures the async context frame when the hook is installed and registers the reaction in it, as the spec's promise reaction would.

It also adds test-whatwg-webstreams-async-context.js, which records the context each underlying source, sink and transformer callback observes across 29 readable, writable, transform, pipe and tee scenarios, so scheduling shortcuts that drop the context get caught. The expectations were taken from v24.18.0 (with and without --no-async-context-frame) and v26.5.1, which agree on all of them. Only the context of each callback is compared, not how callbacks of different streams interleave. The test also fails on the parent of 60e6c84 (the #66906 fix).

Refs: #66906
Refs: #66424


AI generated, reviewed by me

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina
stream: keep async context of pipeTo watchers
e15df5f
The ClosedPromiseHook records that pipeTo() and tee() install as the
[[closedPromise]] of their reader and writer enqueued the watcher from
whoever settled the record. The source-closed, source-errored and
dest-errored steps of pipeTo() therefore ran in the async context of
the code that closed or errored the stream, so the destination's
close() and abort() and the source's cancel() observed the wrong
AsyncLocalStorage store. Capture the async context frame when the
hook is installed and register the reaction in it, as the spec's
promise reaction would.

Add a test that records the context each underlying source, sink and
transformer callback observes across readable, writable, transform,
pipe and tee scenarios, so scheduling shortcuts that drop the context
are caught.

Refs: nodejs#66906
Refs: nodejs#66424
Signed-off-by: Matteo Collina <[email protected]>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams Issues and PRs related to the Web Streams API. labels Oct 27, 2026
This was referenced Oct 27, 2026
stream: keep async context of the pipeTo pump #67054
Merged
stream: keep async context of fromWeb writes #67055
Merged
@codecov

codecov Bot commented Oct 27, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (29bd740) to head (e15df5f).
⚠️ Report is 223 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67052      +/-   ##
==========================================
+ Coverage   90.47%   90.65%   +0.18%     
==========================================
  Files         791      797       +6     
  Lines      277245   278279    +1034     
  Branches    53310    53519     +209     
==========================================
+ Hits       250834   252283    +1449     
+ Misses      16811    16371     -440     
- Partials     9600     9625      +25     
Files with missing lines Coverage Δ
lib/internal/webstreams/readablestream.js 98.36% <100.00%> (+0.25%) ⬆️

... and 140 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aduh95
aduh95 approved these changes Oct 27, 2026
View reviewed changes
@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Oct 27, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 27, 2026
@nodejs-github-bot

nodejs-github-bot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78687/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ShogunPanda
ShogunPanda approved these changes Oct 28, 2026
View reviewed changes
@aduh95 aduh95 added the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 28, 2026
@nodejs-github-bot
nodejs-github-bot merged commit d56c163 into nodejs:main Oct 29, 2026
80 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in d56c163

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 29, 2026
nodejs-github-bot pushed a commit that referenced this pull request Nov 2, 2026
@mcollina
stream: keep async context of fromWeb writes
1206541
Writable.fromWeb() and Duplex.fromWeb() dispatch writes to the
WritableStream directly and complete them through a shared write
tracker. A write issued before the WritableStream had started was
queued and processed from its start step, so the sink ran in the async
context of the code that created the WritableStream, and the tracker
invoked the Node.js write callback synchronously from whatever context
completed the sink write, so the writes and final() it released ran
there too. The promise-based adapter waited for writer.ready and
received the result through a reaction, both in the context of the
Node.js write.

Dispatch writes issued before the start from a writer.ready reaction,
failing them if the stream was closed or errored meanwhile, and deliver
the write callback in the context of the Node.js write, from a reaction
when it completes in another context.

Refs: #66906
Refs: #65548
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67055
Refs: #67052
Refs: #67054
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 11, 2026
@mcollina @aduh95
stream: keep async context of pipeTo watchers
caa48a3
The ClosedPromiseHook records that pipeTo() and tee() install as the
[[closedPromise]] of their reader and writer enqueued the watcher from
whoever settled the record. The source-closed, source-errored and
dest-errored steps of pipeTo() therefore ran in the async context of
the code that closed or errored the stream, so the destination's
close() and abort() and the source's cancel() observed the wrong
AsyncLocalStorage store. Capture the async context frame when the
hook is installed and register the reaction in it, as the spec's
promise reaction would.

Add a test that records the context each underlying source, sink and
transformer callback observes across readable, writable, transform,
pipe and tee scenarios, so scheduling shortcuts that drop the context
are caught.

Refs: #66906
Refs: #66424
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 11, 2026
@mcollina @aduh95
stream: keep async context of fromWeb writes
101e729
Writable.fromWeb() and Duplex.fromWeb() dispatch writes to the
WritableStream directly and complete them through a shared write
tracker. A write issued before the WritableStream had started was
queued and processed from its start step, so the sink ran in the async
context of the code that created the WritableStream, and the tracker
invoked the Node.js write callback synchronously from whatever context
completed the sink write, so the writes and final() it released ran
there too. The promise-based adapter waited for writer.ready and
received the result through a reaction, both in the context of the
Node.js write.

Dispatch writes issued before the start from a writer.ready reaction,
failing them if the stream was closed or errored meanwhile, and deliver
the write callback in the context of the Node.js write, from a reaction
when it completes in another context.

Refs: #66906
Refs: #65548
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67055
Refs: #67052
Refs: #67054
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 11, 2026
2026-11-12, Version 27.0.0-alpha.0.1.0 (Alpha) #67415
Merged
aduh95 pushed a commit that referenced this pull request Nov 12, 2026
@mcollina @aduh95
stream: keep async context of pipeTo watchers
4f2e200
The ClosedPromiseHook records that pipeTo() and tee() install as the
[[closedPromise]] of their reader and writer enqueued the watcher from
whoever settled the record. The source-closed, source-errored and
dest-errored steps of pipeTo() therefore ran in the async context of
the code that closed or errored the stream, so the destination's
close() and abort() and the source's cancel() observed the wrong
AsyncLocalStorage store. Capture the async context frame when the
hook is installed and register the reaction in it, as the spec's
promise reaction would.

Add a test that records the context each underlying source, sink and
transformer callback observes across readable, writable, transform,
pipe and tee scenarios, so scheduling shortcuts that drop the context
are caught.

Refs: #66906
Refs: #66424
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 12, 2026
@mcollina @aduh95
stream: keep async context of fromWeb writes
c9dc9dc
Writable.fromWeb() and Duplex.fromWeb() dispatch writes to the
WritableStream directly and complete them through a shared write
tracker. A write issued before the WritableStream had started was
queued and processed from its start step, so the sink ran in the async
context of the code that created the WritableStream, and the tracker
invoked the Node.js write callback synchronously from whatever context
completed the sink write, so the writes and final() it released ran
there too. The promise-based adapter waited for writer.ready and
received the result through a reaction, both in the context of the
Node.js write.

Dispatch writes issued before the start from a writer.ready reaction,
failing them if the stream was closed or errored meanwhile, and deliver
the write callback in the context of the Node.js write, from a reaction
when it completes in another context.

Refs: #66906
Refs: #65548
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67055
Refs: #67052
Refs: #67054
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 13, 2026
@mcollina @aduh95
stream: keep async context of pipeTo watchers
d5fa3be
The ClosedPromiseHook records that pipeTo() and tee() install as the
[[closedPromise]] of their reader and writer enqueued the watcher from
whoever settled the record. The source-closed, source-errored and
dest-errored steps of pipeTo() therefore ran in the async context of
the code that closed or errored the stream, so the destination's
close() and abort() and the source's cancel() observed the wrong
AsyncLocalStorage store. Capture the async context frame when the
hook is installed and register the reaction in it, as the spec's
promise reaction would.

Add a test that records the context each underlying source, sink and
transformer callback observes across readable, writable, transform,
pipe and tee scenarios, so scheduling shortcuts that drop the context
are caught.

Refs: #66906
Refs: #66424
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 13, 2026
@mcollina @aduh95
stream: keep async context of fromWeb writes
ffddf27
Writable.fromWeb() and Duplex.fromWeb() dispatch writes to the
WritableStream directly and complete them through a shared write
tracker. A write issued before the WritableStream had started was
queued and processed from its start step, so the sink ran in the async
context of the code that created the WritableStream, and the tracker
invoked the Node.js write callback synchronously from whatever context
completed the sink write, so the writes and final() it released ran
there too. The promise-based adapter waited for writer.ready and
received the result through a reaction, both in the context of the
Node.js write.

Dispatch writes issued before the start from a writer.ready reaction,
failing them if the stream was closed or errored meanwhile, and deliver
the write callback in the context of the Node.js write, from a reaction
when it completes in another context.

Refs: #66906
Refs: #65548
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67055
Refs: #67052
Refs: #67054
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Nov 18, 2026
@mcollina
stream: keep async context of the pipeTo pump
9305353
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: #66906
Refs: #65138
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67054
Refs: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 19, 2026
@mcollina @aduh95
stream: keep async context of the pipeTo pump
a4928b2
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: #66906
Refs: #65138
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67054
Refs: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 20, 2026
@mcollina @aduh95
stream: keep async context of the pipeTo pump
9cf89fe
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: #66906
Refs: #65138
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67054
Refs: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
aduh95 pushed a commit that referenced this pull request Nov 20, 2026
@mcollina @aduh95
stream: keep async context of the pipeTo pump
29cdb9d
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: #66906
Refs: #65138
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: #67054
Refs: #67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
This was referenced Nov 20, 2026
2026-11-30, Version 24.23.0 'Krypton' (LTS) #67663
Open
2026-11-30, Version 26.14.0 'Lithium' (LTS) #67664
Open
Renegade334 pushed a commit to Renegade334/node that referenced this pull request Nov 21, 2026
@mcollina @aduh95
stream: keep async context of the pipeTo pump
472d501
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: nodejs#66906
Refs: nodejs#65138
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: nodejs#67054
Refs: nodejs#67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@mcollina @gabylb
stream: keep async context of pipeTo watchers
d590357
The ClosedPromiseHook records that pipeTo() and tee() install as the
[[closedPromise]] of their reader and writer enqueued the watcher from
whoever settled the record. The source-closed, source-errored and
dest-errored steps of pipeTo() therefore ran in the async context of
the code that closed or errored the stream, so the destination's
close() and abort() and the source's cancel() observed the wrong
AsyncLocalStorage store. Capture the async context frame when the
hook is installed and register the reaction in it, as the spec's
promise reaction would.

Add a test that records the context each underlying source, sink and
transformer callback observes across readable, writable, transform,
pipe and tee scenarios, so scheduling shortcuts that drop the context
are caught.

Refs: nodejs#66906
Refs: nodejs#66424
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: nodejs#67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@mcollina @gabylb
stream: keep async context of fromWeb writes
59d941a
Writable.fromWeb() and Duplex.fromWeb() dispatch writes to the
WritableStream directly and complete them through a shared write
tracker. A write issued before the WritableStream had started was
queued and processed from its start step, so the sink ran in the async
context of the code that created the WritableStream, and the tracker
invoked the Node.js write callback synchronously from whatever context
completed the sink write, so the writes and final() it released ran
there too. The promise-based adapter waited for writer.ready and
received the result through a reaction, both in the context of the
Node.js write.

Dispatch writes issued before the start from a writer.ready reaction,
failing them if the stream was closed or errored meanwhile, and deliver
the write callback in the context of the Node.js write, from a reaction
when it completes in another context.

Refs: nodejs#66906
Refs: nodejs#65548
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: nodejs#67055
Refs: nodejs#67052
Refs: nodejs#67054
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@mcollina @gabylb
stream: keep async context of the pipeTo pump
2d13a2c
The pipeTo() pump re-enters from the destination's ready hook, which
writableStreamUpdateBackpressure invokes synchronously, and from the
chunk steps of its read request. Both run in the async context of the
code that cleared the backpressure or enqueued the chunk, so the
source's pull() and the writes issued after a resumption observed that
context instead of the one of the pipeTo() call, as they did with the
promise-based pump. Capture the async context frame when the pipe starts
and run the pump in it.

Refs: nodejs#66906
Refs: nodejs#65138
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: nodejs#67054
Refs: nodejs#67052
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Paolo Insogna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ShogunPanda ShogunPanda ShogunPanda approved these changes
@aduh95 aduh95 aduh95 approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. needs-ci PRs that need a full CI run. web streams Issues and PRs related to the Web Streams API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@mcollina @nodejs-github-bot @ShogunPanda @aduh95
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.