Skip to content

http2: increase default window sizes#64623

Open
mcollina wants to merge 5 commits into
nodejs:mainfrom
mcollina:increase-http2-window-size
Open

http2: increase default window sizes#64623
mcollina wants to merge 5 commits into
nodejs:mainfrom
mcollina:increase-http2-window-size

Conversation

@mcollina

Copy link
Copy Markdown
Member

Increase the default HTTP/2 stream window from 64KB (65535) to 4MB
(4194304) and the default local connection window to 32MB (33554432).

The default 64KB window limits throughput on high-latency connections
to window_size / RTT. With a 250ms RTT, throughput is limited to
256KB/s. The new defaults improve throughput to 16MB/s (128Mbps)
for the stream window and 128MB/s (1Gbps) for the connection window.

Fixes #38426

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/http2
  • @nodejs/net
  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 20, 2026
@mcollina
mcollina requested review from pimterry, ronag and trivikr and removed request for pimterry July 20, 2026 12:33
Comment thread src/node_http2.cc Outdated
// to window_size / RTT. With a 32MB connection window, throughput is
// significantly improved. See https://github.com/nodejs/node/issues/38426
CHECK_EQ(nghttp2_session_set_local_window_size(
session, NGHTTP2_FLAG_NONE, 0, 33554432), 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's a pre-existing issue that this exposes: you can't configure this in advance. You can only control the connection window with session.setLocalWindowSize once you have a session, but at that point this initial WINDOW_UPDATE has already been sent, and shrinking the window isn't effective as shown in the tests here (it just blocks further updates, it can't reduce what's already been sent). The stream window is configurable in advance (it's a SETTINGS parameter) but this connection window isn't.

That already existed implicitly but it was kind of OK when the initial window was small, but it's a real problem with a very large initial window I think, since there's basically no way to override this to make it any smaller again if you need to.

Can we add client & server options for this, so it can be configured before the first WINDOW_UPDATE is sent somehow?

Comment thread src/node_http2.cc Outdated
// to window_size / RTT. With a 32MB connection window, throughput is
// significantly improved. See https://github.com/nodejs/node/issues/38426
CHECK_EQ(nghttp2_session_set_local_window_size(
session, NGHTTP2_FLAG_NONE, 0, 33554432), 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: would be nicer to extract this as a constant

@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.14%. Comparing base (ace91de) to head (6bbb6b2).
⚠️ Report is 107 commits behind head on main.

Files with missing lines Patch % Lines
src/stream_pipe.cc 0.00% 6 Missing and 1 partial ⚠️
src/node_http2.cc 0.00% 0 Missing and 1 partial ⚠️
src/stream_base.cc 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64623      +/-   ##
==========================================
- Coverage   90.23%   90.14%   -0.10%     
==========================================
  Files         741      743       +2     
  Lines      241681   242321     +640     
  Branches    45547    45626      +79     
==========================================
+ Hits       218075   218434     +359     
- Misses      15141    15369     +228     
- Partials     8465     8518      +53     
Files with missing lines Coverage Δ
lib/internal/http2/core.js 94.87% <100.00%> (+0.06%) ⬆️
src/node_http2.h 92.26% <ø> (+0.21%) ⬆️
src/node_http2.cc 81.82% <0.00%> (-0.35%) ⬇️
src/stream_base.cc 79.92% <50.00%> (-0.12%) ⬇️
src/stream_pipe.cc 59.63% <0.00%> (+0.09%) ⬆️

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

@mcollina
mcollina force-pushed the increase-http2-window-size branch 2 times, most recently from 5c9bc03 to 4351b51 Compare July 20, 2026 16:48
@mcollina

Copy link
Copy Markdown
Member Author

Both addressed:

  1. Extracted DEFAULT_SETTINGS_LOCAL_CONNECTION_WINDOW_SIZE = 33554432 as a named constant in src/node_http2.h and used it in src/node_http2.cc.
  2. The pre-existing issue about not being able to configure the connection window in advance is noted — the initial WINDOW_UPDATE is sent at session creation before setLocalWindowSize can be called. This is a known limitation of the current API.

@mcollina
mcollina force-pushed the increase-http2-window-size branch from 4351b51 to 31761a0 Compare July 20, 2026 18:25

@RafaelGSS RafaelGSS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't it be semver-major PRs that contain breaking changes and should be released in the next major version. ?

@mcollina mcollina added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 20, 2026
@mcollina

Copy link
Copy Markdown
Member Author

yes

@mcollina
mcollina force-pushed the increase-http2-window-size branch 3 times, most recently from 70882db to bd4cbd3 Compare July 21, 2026 16:44
@pimterry

Copy link
Copy Markdown
Member

The pre-existing issue about not being able to configure the connection window in advance is noted — the initial WINDOW_UPDATE is sent at session creation before setLocalWindowSize can be called. This is a known limitation of the current API.

I do think this would be useful, but doesn't need to block this - I'll open a separate PR.

@mcollina
mcollina force-pushed the increase-http2-window-size branch from bd4cbd3 to 86b969b Compare July 21, 2026 22:16
Increase the default HTTP/2 stream window from 64KB (65535) to 4MB
(4194304) and the default local connection window to 32MB (33554432).

The default 64KB window limits throughput on high-latency connections
to window_size / RTT. With a 250ms RTT, throughput is limited to
256KB/s. The new defaults improve throughput to 16MB/s (128Mbps)
for the stream window and 128MB/s (1Gbps) for the connection window.

Fixes: nodejs#38426
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the increase-http2-window-size branch from 86b969b to d0c68ba Compare July 22, 2026 09:39

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CI failure seems related to the change here; test-http2-respond-with-file-connection-abort is failing across multiple systems and that isn't a known flake. Leaving a request changes to this gets fixed before landing.

@Ethan-Arrowood

Copy link
Copy Markdown
Contributor

I was able to reproduce locally (5/12 runs of that test crashes with SIGSEGV). Assisted by Claude, the fix is possible a null-guard at stream_base.cc:757 (if (req_wrap == nullptr) return; or equivalent)

@pimterry

Copy link
Copy Markdown
Member

I was a bit surprised by that flake coming out of a change like this, so I looked into it more - I think it is an existing clear bug, just made more visible by this change, but interestingly there's actually a reported issue (#56825) that seems to have the same or very similar crash in ReportWritesToJSStreamListener::OnStreamAfterReqFinished which suggests this is reachable in normal use already, and presumably fixing this would helpfully fix that bug too 😄

When a stream is destroyed while a synchronous write is in flight
from StreamPipe::ProcessData, ReportWritesToJSStreamListener::
OnStreamAfterReqFinished can be called with a null stream_ or a
null req_wrap, causing a null pointer dereference. This race
becomes more likely with larger HTTP/2 windows (e.g., nodejs#38426)
because more data is in flight during session teardown.

Add early-return guards for both cases to prevent the crash.

Refs: nodejs#38426
Refs: nodejs#56825
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the increase-http2-window-size branch from 7b18703 to 16a74ad Compare July 23, 2026 14:31
@mcollina

mcollina commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

I investigated the segfault in test-http2-respond-with-file-connection-abort.js. The root cause is a pre-existing null deref in ReportWritesToJSStreamListener::OnStreamAfterReqFinished (src/stream_base.cc:752). When StreamPipe::ProcessData performs a synchronous write (write completes immediately without going through the libuv event loop), it calls writable_listener_.OnStreamAfterWrite(nullptr, ...) which passes a null req_wrap down to OnStreamAfterReqFinished. If the HTTP/2 stream has already been destroyed (which happens earlier with larger windows because more data is in flight), both stream_ and req_wrap can be null, causing a crash.

This is the same family of crash as #56825. Larger HTTP/2 windows make the race much more likely because more data is pipelined before session teardown completes.

I added early-return null guards for both stream_ and req_wrap in OnStreamAfterReqFinished, which prevents the crash. The test now passes consistently.

Also fixed test-http2-perf_hooks.js which expected a strict framesReceived count of 7 on the client, but with the additional WINDOW_UPDATE frame from the connection window increase, the count can be 8 on some platforms. Relaxed to >= 7.

Also fixed test-stream-pipeline-http2.js timeout — the root cause was a pending_writes_ underflow in StreamPipe::WritableListener::OnStreamDestroy. When the writable sink is destroyed while there are pending writes, OnStreamDestroy previously reset pending_writes_ to 0, causing OnStreamAfterWrite to decrement the counter below 0. The pending_writes_ == 0 completion check then permanently failed, so the oncomplete callback was never called. This race became much more likely with larger HTTP/2 windows because more writes are in flight during session teardown.

Fixes in commits:

  • 16a74ad: null guard fix in stream_base.cc
  • f2a6a04: relaxed framesReceived assertion in perf_hooks test
  • 2e07502: pending_writes underflow fix in stream_pipe.cc

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026

@Ethan-Arrowood Ethan-Arrowood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 23, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

mcollina added 3 commits July 24, 2026 08:20
With the default window size increase, the server sends an additional
WINDOW_UPDATE frame during session setup, increasing the frames received
by the client from 7 to 8 on some platforms. Relax the assertion to
check >= 7 instead of strict equality.

Refs: nodejs#38426
Signed-off-by: Matteo Collina <hello@matteocollina.com>
When the writable sink is destroyed while there are still pending
writes, WritableListener::OnStreamDestroy previously reset
pending_writes_ to 0. This caused OnStreamAfterWrite to decrement
the counter below 0, making the pending_writes_ == 0 completion
check fail permanently — the oncomplete callback was never called,
causing a timeout.

Fix by:
1. Not resetting pending_writes_ in OnStreamDestroy — let
   OnStreamAfterWrite track completion naturally.
2. Using sink_destroyed_ flag in Unpipe to always remove the
   writable listener regardless of pending_writes_ count.
3. Using <= 0 (instead of == 0) when sink_destroyed_ is set,
   and guarding RemoveStreamListener against a null stream.

This race became more likely with larger HTTP/2 windows (nodejs#38426)
because more writes are in flight when session teardown begins.

Refs: nodejs#38426
Refs: nodejs#56825
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Signed-off-by: Matteo Collina <hello@matteocollina.com>
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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increase HTTP/2 window size by default

10 participants