http2: settle pending write callbacks on stream destroy - #66016
Open
mcollina wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66016 +/- ##
==========================================
+ Coverage 90.17% 90.20% +0.03%
==========================================
Files 770 785 +15
Lines 264483 269356 +4873
Branches 50262 51515 +1253
==========================================
+ Hits 238491 242970 +4479
+ Misses 16981 16899 -82
- Partials 9011 9487 +476
🚀 New features to boost your workflow:
|
mcollina
force-pushed
the
fix-http2-close-while-writing
branch
from
September 13, 2026 17:27
4720388 to
2e34a6f
Compare
When a stream is destroyed while a write is still in flight, nghttp2 may have handed the data to the socket and never report the write completion once the stream or session tears down. That leaves the write callback unresolved, the Writable stuck, and the event loop never drains, which times out test-http2-close-while-writing on macOS. Settle the in-flight write in Http2Stream._destroy by invoking its callback with the destroy error and resetting writePending. A later native completion callback is then a no-op because writeCb is null and writePending is 0, so the settle is idempotent. Passing the error rather than null also drains any buffered writes. Fixes: nodejs#58252 Signed-off-by: Matteo Collina <hello@matteocollina.com> Assisted-by: pi-coding-agent
mcollina
force-pushed
the
fix-http2-close-while-writing
branch
from
September 13, 2026 19:23
2e34a6f to
9d88a60
Compare
jasnell
approved these changes
Sep 13, 2026
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.
When an HTTP/2 stream is destroyed while a write is still in flight, nghttp2 may have already handed the data off to the socket and never report the write's completion once the stream or session tears down. In that case the native completion callback that resolves the Writable write (stream[kState].writeCb) is never invoked, so the Writable stays stuck and the event loop never drains, causing test-http2-close-while-writing to time out on macOS.
In Http2Stream._destroy, settle any write that is still in flight by invoking its callback with the destroy error and resetting writePending. A later native completion callback is then a no-op because writeCb is null and writePending is 0, so the settle is idempotent. Passing the error (rather than null) also drains any buffered writes.
Fixed: #58252
Assisted-by: pi-coding-agent