GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: fix eos() for HTTP/2 streams after clean end & close by pimterry · Pull Request #67553 · nodejs/node

Conversation

@pimterry

@pimterry pimterry commented Nov 17, 2026

Copy link
Copy Markdown
Member

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 like finished(), pipeline(), and async iteration.
  • When first called, this checks stream.closed, and if it's already closed but 'end' hasn't been emitted then it treats this as a PREMATURE_CLOSE error.
  • HTTP/2 stream's closed property represents whether the actual stream is closed on the wire. It predates the Node stream closed field, which is only set after 'close' is emitted.
  • If an HTTP/2 server sends a complete data stream (with a clean end) after a completed request, immediately closing the stream on the wire, but the client doesn't immediately start reading, then h2Stream.closed becomes true before 'end' has been emitted, and so eos() reports this as a premature close.
  • For a normal Node stream, in the equivalent case 'close' wouldn't fire and closed would stay false until the data was actually read (the close is implicitly queued behind the data) so eos() wouldn't treat this as an error.
  • That's correct - this shouldn't be an error, and it shouldn't be an error in the HTTP/2 case either. The data is still there, and reading will be successful to the end of the stream.
  • Very similar logic applies to '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:

  • It defines an isEndPending function, to check whether a stream has happily ended data buffered already.
  • eos() now checks isEndPending for 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).
  • In both cases, if there's a buffered successful end, it doesn't consider the stream failed, and instead continues its normal logic (waiting for other events to fire, either when the data is read later or when an actual error appears).

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pimterry
http2: fix eos() for HTTP/2 streams after clean end & close
34b064d
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 <[email protected]>
@nodejs-github-bot

nodejs-github-bot commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/streams
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to Node.js streams. labels Nov 17, 2026
@pimterry pimterry mentioned this pull request Nov 17, 2026
stream: recompute the close error when eos() defers #65689
Closed
@pimterry

pimterry commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

cc @nodejs/http2 as well (streams code, but fix only applies to HTTP/2 streams I think)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry pimterry mentioned this pull request Nov 17, 2026
http2: don't fail response reads after clean RST_STREAM #67558
Merged
@codecov

codecov Bot commented Nov 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.68%. Comparing base (1c40cfa) to head (34b064d).
⚠️ Report is 53 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/internal/streams/end-of-stream.js 99.76% <100.00%> (+0.01%) ⬆️

... and 45 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Nov 18, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@pimterry pimterry mentioned this pull request Nov 18, 2026
http2: async iterator rejects complete buffered response after NO_ERROR reset with request side open #66693
Closed
jasnell
jasnell approved these changes Nov 18, 2026
View reviewed changes
@pimterry pimterry added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 18, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/79252/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry pimterry added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 19, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 19, 2026
@nodejs-github-bot

nodejs-github-bot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/79297/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pimterry pimterry added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
@nodejs-github-bot
nodejs-github-bot merged commit db671bb into nodejs:main Nov 19, 2026
84 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Landed in db671bb

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
aduh95 pushed a commit that referenced this pull request Nov 20, 2026
@pimterry @aduh95
http2: fix eos() for HTTP/2 streams after clean end & close
6bde4f8
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 <[email protected]>
PR-URL: #67553
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2026-11-25, Version 27.0.0-alpha.0.2.0 (Alpha) #67757
Merged
@pimterry
pimterry deleted the fix-stream-premature-close branch November 26, 2026 16:09
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@pimterry @gabylb
http2: fix eos() for HTTP/2 streams after clean end & close
ac02dc5
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 <[email protected]>
PR-URL: nodejs#67553
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@jasnell jasnell jasnell approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

needs-ci PRs that need a full CI run. stream Issues and PRs related to Node.js streams.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

http2: async iterator rejects complete buffered response after NO_ERROR reset with request side open http2: async iteration reports premature close with buffered responses in v26.3.0+ and v24.20.0

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@pimterry @nodejs-github-bot @mcollina @jasnell
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.