stream: pass ERR_STREAM_WRITE_AFTER_END to .end(cb) after end#62949
Open
maruthang wants to merge 2 commits intonodejs:mainfrom
Open
stream: pass ERR_STREAM_WRITE_AFTER_END to .end(cb) after end#62949maruthang wants to merge 2 commits intonodejs:mainfrom
maruthang wants to merge 2 commits intonodejs:mainfrom
Conversation
`stream.end(cb)` called on a stream that has already been ended did not propagate ERR_STREAM_WRITE_AFTER_END to the callback. Instead, the callback was queued for the eventual `finish` event and called with `null`, which was inconsistent with `.write(chunk, cb)` and `.end(chunk, cb)` after end, both of which correctly call `cb` with ERR_STREAM_WRITE_AFTER_END. In `Writable.prototype.end`, when the stream is already ending and not yet finished or destroyed and a user callback was supplied, set the error to ERR_STREAM_WRITE_AFTER_END so the existing `process.nextTick(cb, err)` path delivers it. The forgiving behavior of `.end()` without a callback being called multiple times is preserved (no call to errorOrDestroy). Fixes: nodejs#33684 Signed-off-by: Maruthan G <[email protected]>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62949 +/- ##
==========================================
- Coverage 89.66% 89.65% -0.01%
==========================================
Files 706 706
Lines 219391 219399 +8
Branches 42068 42073 +5
==========================================
Hits 196712 196712
- Misses 14578 14590 +12
+ Partials 8101 8097 -4
🚀 New features to boost your workflow:
|
The previous version always synthesized ERR_STREAM_WRITE_AFTER_END when kEnding was set, which broke test-stream-writable-end-cb-error block 1: a writable whose underlying _write errors with `_err`, and whose `.end(cb1)` and `.end(cb2)` are both expected to receive that underlying error via kOnFinished. Tighten the condition to only synthesize WRITE_AFTER_END when the stream has no in-flight write (kWriting), no buffered data (kBuffered), no stored error (kErrored), and an empty buffer length. In any of those cases there is real pending state that will surface a meaningful error through the existing kOnFinished cascade, so the cb should be queued and receive that real error instead. Signed-off-by: Maruthan G <[email protected]>
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.
stream.end(cb)called on a stream that has already been ended didnot propagate ERR_STREAM_WRITE_AFTER_END to the callback. Instead,
the callback was queued for the eventual
finishevent and calledwith
null, which was inconsistent with.write(chunk, cb)and.end(chunk, cb)after end, both of which correctly callcbwithERR_STREAM_WRITE_AFTER_END.
In
Writable.prototype.end, when the stream is already ending andnot yet finished or destroyed and a user callback was supplied,
set the error to ERR_STREAM_WRITE_AFTER_END so the existing
process.nextTick(cb, err)path delivers it. The forgivingbehavior of
.end()without a callback being called multipletimes is preserved (no call to errorOrDestroy).
Fixes: #33684
Note: I was unable to run the test suite locally on this Windows host (no built
out/Release/node, and system Node v20 is too old for this repo'stest/common/index.jswhich usesgetCallSites). Both files lint clean and passnode --check; logic verified by walk-through against current writable.js plus the existingtest-stream-writable-end-cb-error.js(which already encodes the post-fix expectation). Looking forward to CI verification.