Skip to content

[v26.x] stream: keep async context of parked writes - #66915

Open
mcollina wants to merge 1 commit into
nodejs:v26.x-stagingfrom
mcollina:backport-66907-v26
Open

mcollina wants to merge 1 commit into
nodejs:v26.x-stagingfrom
mcollina:backport-66907-v26

Conversation

@mcollina

@mcollina mcollina commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Backport of #66907 (not landed on main yet, hence draft).

v26.x still has the async_hooks-based AsyncLocalStorage (--no-async-context-frame; removed on main in #63641), where AsyncContextFrame is a no-op. So on top of the main change, when async hooks are enabled at park time (which includes the legacy AsyncLocalStorage) the continuation is registered on a promise created at park time and resolved on unpark, restoring the pre-#65625 promise-reaction context. It runs at the same microtask position as before. Otherwise the frame capture from main is used, and the cheap path stays allocation-free.

Adds test-whatwg-transformstream-parked-write-async-context-legacy.js, which runs the same assertions under --no-async-context-frame.

Verified locally on this branch:

default:                         a:writer b:writer c:writer d:writer e:writer flush:writer
--no-async-context-frame:        a:writer b:writer c:writer d:writer e:writer flush:writer
ACF + enabled user async hook:   a:writer b:writer c:writer d:writer e:writer flush:writer
reverse (reader in als.run):     a:none b:none c:none flush:none   (both modes)

whatwg/webstream tests, WPT streams, async-local-storage and async-hooks suites pass.

Alternative: #66914 reverts the regressing commits on v26.x instead. Only one of the two should land.

Refs: #66906
Refs: #66907


AI generated, reviewed by me

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. v26.x Issues that can be reproduced on v26.x or PRs targeting the v26.x-staging branch. web streams Issues and PRs related to the Web Streams API. labels Oct 22, 2026
A TransformStream write that parks on backpressure was resumed from
the read that lifted the backpressure, so transform(), the writes
queued behind it, and flush() ran in the reader's async context
instead of the writer's. Capture the async context frame when the
write parks and restore it while the continuation runs, matching the
context the spec's [[backpressureChangePromise]] reaction had.

When async hooks are enabled, which includes the async_hooks-based
AsyncLocalStorage used with --no-async-context-frame, the continuation
is instead registered on a promise created at park time and resolved
on unpark, as before.

Fixes: nodejs#66906

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina marked this pull request as ready for review October 22, 2026 15:52
@codecov

codecov Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.75%. Comparing base (ca26282) to head (c405372).
⚠️ Report is 1275 commits behind head on v26.x-staging.

Additional details and impacted files
@@                Coverage Diff                @@
##           v26.x-staging   #66915      +/-   ##
=================================================
+ Coverage          90.24%   90.75%   +0.51%     
=================================================
  Files                729      775      +46     
  Lines             242760   273485   +30725     
  Branches           46044    52521    +6477     
=================================================
+ Hits              219073   248210   +29137     
- Misses             15133    16143    +1010     
- Partials            8554     9132     +578     
Files with missing lines Coverage Δ
lib/internal/webstreams/transformstream.js 98.76% <100.00%> (+0.19%) ⬆️

... and 413 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.

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. v26.x Issues that can be reproduced on v26.x or PRs targeting the v26.x-staging branch. web streams Issues and PRs related to the Web Streams API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants