Skip to content

http2: don't suppress internal termination detection on a peer GOAWAY - #66641

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:http2-fix-goaway-detector
Open

mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:http2-fix-goaway-detector

Conversation

@mcollina

@mcollina mcollina commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

When a peer sends GOAWAY(NO_ERROR), core.js calls session.close(), which
sets both graceful_close_initiated_ and goaway_initiated_. Those flags
can be set without any application code, and once set are never reset, so
they could permanently disarm the detector that tears down the session when
nghttp2 internally terminates it after a protocol error (for example an
oversized frame).

This makes the detector compare the GOAWAY error code against the code the
session requested through session.goaway() / session.close(). A
peer-triggered graceful close submits GOAWAY(NO_ERROR); if nghttp2 later
emits a frame carrying a different error code it was not requested by us,
which indicates an internal termination. In that case the session is torn
down and the resulting error is surfaced, as it would be without the prior
peer GOAWAY.

Defense-in-depth hardening; no test is included because the triggering
scenario is not reproducibly exercised by the default build.


AI generated, reviewed by me.

When a peer sends GOAWAY(NO_ERROR), lib/internal/http2/core.js calls
session.close(), which sets both graceful_close_initiated_ and
goaway_initiated_. Those flags can be set without any application code
and, once set, are never reset, so they permanently disarmed the
detector that tears down the session when nghttp2 internally terminates
it after a protocol error (e.g. an oversized frame).

The detector now compares the GOAWAY error code against the code this
session requested through session.goaway()/session.close(). A
peer-triggered graceful close submits GOAWAY(NO_ERROR); if nghttp2 later
emits a frame carrying a different error code it was not requested by
us, which indicates an internal termination. In that case the session is
torn down and the resulting error is surfaced, as it would be without
the prior peer GOAWAY.

Assisted-by: pi
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http2
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. http2 Issues and PRs related to the http2 subsystem. needs-ci PRs that need a full CI run. labels Oct 10, 2026
@mcollina
mcollina requested a review from pimterry October 10, 2026 10:14
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.44%. Comparing base (ebef774) to head (8cf2198).
⚠️ Report is 460 commits behind head on main.

Files with missing lines Patch % Lines
src/node_http2.cc 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66641      +/-   ##
==========================================
+ Coverage   90.28%   90.44%   +0.15%     
==========================================
  Files         790      791       +1     
  Lines      271642   276613    +4971     
  Branches    51846    53128    +1282     
==========================================
+ Hits       245260   250177    +4917     
+ Misses      16889    16853      -36     
- Partials     9493     9583      +90     
Files with missing lines Coverage Δ
src/node_http2.h 92.47% <100.00%> (+0.08%) ⬆️
src/node_http2.cc 82.05% <75.00%> (-0.03%) ⬇️

... and 236 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. http2 Issues and PRs related to the http2 subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants