stream: fix pipeTo assert when writer is released during microtask - #63733
Open
colinaaa wants to merge 2 commits into
Open
stream: fix pipeTo assert when writer is released during microtask#63733colinaaa wants to merge 2 commits into
colinaaa wants to merge 2 commits into
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
colinaaa
force-pushed
the
fix-stream-shutdown
branch
from
September 4, 2026 04:35
eedd317 to
de4d49d
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.
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