Repository navigation
Conversation
Previously this could fail - not having read 'end' when the close arrived was treated as a premature close error for finished() and related APIs, even though the body data was cleanly ended and complete. We now check whether there is a clean end buffered. If so, we wait until it's read before evaluating whether the stream ended cleanly. Signed-off-by: Tim Perry <pimterry@gmail.com>
Collaborator
|
Review requested:
|
Member
Author
|
cc @nodejs/http2 as well (streams code, but fix only applies to HTTP/2 streams I think) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67553 +/- ##
==========================================
+ Coverage 90.67% 90.68% +0.01%
==========================================
Files 800 800
Lines 280889 281019 +130
Branches 54274 54303 +29
==========================================
+ Hits 254684 254850 +166
+ Misses 16295 16262 -33
+ Partials 9910 9907 -3
🚀 New features to boost your workflow:
|
jasnell
approved these changes
Nov 18, 2026
Collaborator
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.
This fixes #65677, replacing #65689. The latter does also fix that repro and a subset of the affected cases, but it's not complete and it's now stalled in review.
It also fixes #66693 for v26 (but not fully for v27 & main yet, which need a non-backportable fix to cover the new breaking change semantics in #63249 too - separate PR for that coming shortly).
The problem:
eos()takes a stream and a callback, and calls the callback when the stream cleanly completes, or with an error if not. This is used internally to implement various public APIs likefinished(),pipeline(), and async iteration.stream.closed, and if it's already closed but'end'hasn't been emitted then it treats this as a PREMATURE_CLOSE error.closedproperty represents whether the actual stream is closed on the wire. It predates the Node streamclosedfield, which is only set after'close'is emitted.h2Stream.closedbecomestruebefore'end'has been emitted, and soeos()reports this as a premature close.'close'wouldn't fire andclosedwould stay false until the data was actually read (the close is implicitly queued behind the data) soeos()wouldn't treat this as an error.'aborted'events while the full data is already buffered, this is the http2: async iterator rejects complete buffered response after NO_ERROR reset with request side open #66693 case.This PR fixes all that:
isEndPendingfunction, to check whether a stream has happily ended data buffered already.eos()now checksisEndPendingfor streams that are already closed (fixing http2: async iteration reports premature close with buffered responses in v26.3.0+ and v24.20.0 #65677) and for streams that are later aborted (fixing http2: async iterator rejects complete buffered response after NO_ERROR reset with request side open #66693).This improves on the fix in #65689 for #65677, which only handled the case where the data was all read within the next tick, and still treated this as an error otherwise.