Repository navigation
fix(h2): reset aborted streams with CANCEL - #6201
Open
gabedemesa wants to merge 2 commits into
Open
gabedemesa wants to merge 2 commits into
gabedemesa wants to merge 2 commits into
Conversation
abort() closed the stream with the default NO_ERROR code and then destroyed it synchronously. When the request body is still queued, Node defers a NO_ERROR RST_STREAM until the body has been written, and the synchronous destroy means that never happens, so the peer is never told the stream is gone. Close with NGHTTP2_CANCEL, the code for a stream that is no longer needed, which Node submits immediately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: gdemesa <gdemesa@opengov.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: gdemesa <gdemesa@opengov.com>
metcoder95
approved these changes
Nov 12, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6201 +/- ##
==========================================
- Coverage 91.68% 91.67% -0.01%
==========================================
Files 113 113
Lines 44449 44442 -7
==========================================
- Hits 40751 40744 -7
Misses 3698 3698 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
|
Thanks for the review! This is approved and CI is green. Could a collaborator land it when convenient? |
This branch has not been deployed
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 relates to...
Refs #6181, nodejs/node#67363
Rationale
abort()inlib/dispatcher/client-h2.jscloses the stream with the defaultNO_ERRORcode and then destroys it synchronously. When the request body is still queued, Node defers aNO_ERRORRST_STREAM until the body has been written, and the synchronous destroy means it is never sent. On affected Node versions this leaves the stream open in nghttp2, which can then loop on empty DATA frames until the process runs out of memory (nodejs/node#67363, fixed in Node by nodejs/node#67372).NGHTTP2_CANCELis the code for a stream that is no longer needed, and Node submits it immediately, so aborts no longer depend on the Node fix.Changes
Features
N/A
Bug Fixes
NGHTTP2_CANCEL, and correct the comment that saidclose()had already queued the RST_STREAM.test/http2-abort-rst-cancel.js: aborting a request whose body is held by flow control must reset the stream with CANCEL. Without the change the peer sees code0.docs/docs/api/Client.mdthat an aborted HTTP/2 request resets its stream withCANCEL.Breaking Changes and Deprecations
N/A
Testing
On Node v26.12.1, the reproduction from #6181 (concurrent
fetch()uploads aborted mid-body) runs away withmainand stays bounded with this change. ESLint is clean. Locally,test/h2-disconnect-guard.js,test/http2-max-concurrent-streams-zero-unref.js,test/http2-dispatcher.jsandtest/http2-connection.jsfail or time out identically onmain, so I could not use them to check this change; the other HTTP/2 tests I ran pass.Benchmarks
The change only runs when a request is aborted.
Aborted uploads (32 KB
fetch()POSTs over HTTP/2, aborted on the next tick, 20,000 requests, 32 concurrent, three runs each). This used Nodemainwith nodejs/node#67372 applied, becausemainof undici runs away on released Node versions in this scenario:mainbenchmarks/benchmark-http2.js(SAMPLES=30 CONNECTIONS=50, Node v26.12.1), which does not abort requests:mainThe differences go in both directions and are run-to-run variation; the changed code is not reached in this benchmark. Both on macOS arm64.
Status
🤖 Generated with Claude Code