← Back to Pull requests

http2: fix eos() for HTTP/2 streams after clean end & close #67553

Closed
unknown closed this pull request without merging on Nov 19, 2026 17:41 UTC
View on GitHub
unknown unknown commented on Nov 17, 2026 17:35 UTC
Author

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 https://github.com/nodejs/node/pull/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 #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 #65677) and for streams that are later aborted (fixing #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.

Diff: 314 lines (+235 / -79) across 3 files Reviewer: mcollina Review duration: 2885m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 314 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.344
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #67553"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 40.3% (MEDIUM) · Higher = larger blast radius
40.3%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 15.9% · Safe to merge
15.9%
Repository