stream: recompute the close error when eos() defers - #65689
Open
bitpshr wants to merge 1 commit into
Open
Conversation
When eos() is called on a stream that has already closed, the premature close error was computed right away and then delivered a tick later. A closed stream can still hold data in its readable buffer, so anything that consumes the buffer in between, such as async iteration starting, left the callback reporting a state that no longer applied. HTTP/2 responses that were fully buffered before the stream closed normally failed with ERR_STREAM_PREMATURE_CLOSE. Recompute the result inside the deferred callback instead, which is what the 'close' handler in the same file already does. Only the closed stream branch is affected; the others capture an already emitted error that cannot go stale. Fixes: nodejs#65677 Signed-off-by: Paul Bouchon <mail@bitpshr.net>
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65689 +/- ##
==========================================
- Coverage 90.07% 90.06% -0.01%
==========================================
Files 754 754
Lines 256395 256406 +11
Branches 48499 48504 +5
==========================================
- Hits 230937 230932 -5
- Misses 16569 16578 +9
- Partials 8889 8896 +7
🚀 New features to boost your workflow:
|
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.
Fixes: #65677
Great report, the analysis in the issue is spot on and made this easy to confirm.
When
eos()runs against a stream that has already closed, it computed the premature close error immediately and then delivered it on the next tick. A closed stream can still be holding its whole body in the readable buffer, so anything that drains that buffer in between, such as async iteration starting up, leaves the callback reporting a state that no longer applies. An HTTP/2 response that was fully buffered before the stream closed normally fails withERR_STREAM_PREMATURE_CLOSE.This recomputes the result inside the deferred callback instead, which is what the
'close'handler further down the same file already does. Only the already-closed branch is affected. The other branches capture an error that was already emitted, so they cannot go stale, and the synchronous callback path returns before the tick.Verification, since this sits under a lot of streams:
ERR_STREAM_PREMATURE_CLOSEto passing, and v22 passes it both ways as a control.ERR_STREAM_PREMATURE_CLOSE, so it is not passing vacuously.parallelandsequentialruns on patched and unpatched builds produced nearly disjoint failure sets, 9 unique to patched and 14 unique to baseline, with only a local fixture issue common to both. The unpatched run failed more tests than the patched one. A handful of TLS tests appeared in the patched run, so I ran those five six more times against the patched build and they passed every time.Worth flagging that the reporter suspects #62394 / cbee0de as the origin, which matches the version boundary in their table, so v24.x and v26.x are likely to want this too.