Repository navigation
Conversation
pipeTo defers each slow-path write to a microtask so it does not run synchronously during enqueue(). A race allows the pipe to shut down and release its writer after the write is scheduled but before it runs. The deferred write then hits an ERR_INTERNAL_ASSERTION because writer[[stream]] is undefined. Skip the deferred write when shutdown has already started. Fixes: nodejs#63732 Signed-off-by: Qingyu Wang <wangqingyu.c0l1n@bytedance.com> Assisted-by: Codex
The shuttingDown guard added by the previous commit is too broad: it also skips an already-read chunk while the destination is still writable. The WHATWG Streams spec requires pipeTo to write such chunks during shutdown. Check writer[kState].stream instead. It becomes undefined only after finalize() releases the writer, which is precisely the assertion case. Add a regression test that aborts after enqueue() and verifies that the already-read chunk is written. Signed-off-by: Qingyu Wang <wangqingyu.c0l1n@bytedance.com> Assisted-by: Codex
eedd317 to
de4d49d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #63733 +/- ##
=======================================
Coverage 90.06% 90.06%
=======================================
Files 769 769
Lines 261316 261317 +1
Branches 49622 49628 +6
=======================================
+ Hits 235351 235352 +1
+ Misses 16998 16997 -1
- Partials 8967 8968 +1
🚀 New features to boost your workflow:
|
|
@mcollina Thanks for the review! The Jenkins CI run failed on ARM and Windows, but I don't have access to the logs: https://ci.nodejs.org/job/node-test-pull-request/77173/ Could you help check the failures and rerun CI if they are unrelated to this change? I'm happy to rebase if needed. |
|
@mcollina Thanks for rerunning CI! The latest run is now green: https://ci.nodejs.org/job/node-test-pull-request/78643/ Could you please add this PR to the commit queue when you have a chance? Thanks! |
Commit Queue failedThis pull request has multiple commits, but no landing policy was selected. Add
commit-queue-squash
The pull request was removed from the Commit Queue and labeled
commit-queue-failed
Full Commit Queue output |
|
@mcollina The queue stopped because this PR has two commits but no landing policy label. Could you please add |
Summary
The deferred write introduced by #61800 wraps the write operation in
queueMicrotask(). A race condition exists where the pipe can shutdown and release the writer between when[kChunk]schedules the microtask and when it executes, causing anERR_INTERNAL_ASSERTIONbecausewriter[[stream]]is undefined.Fix by checking
writer[kState].stream === undefinedin the deferred microtask before attempting the write. This condition is only true afterfinalize()has released the writer, precisely targeting the crash without interfering with the spec requirement that already-read chunks are written to a still-writable destination during shutdown.Fixes: #63732