Skip to content

Commit f0bee9b

Browse files
committed
http2: set default maxConcurrentStreams
Set the default maxConcurrentStreams to NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS. PR-URL: #29833 Fixes: #29763 Refs: nghttp2/nghttp2@16c4611 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
1 parent 24011de commit f0bee9b

8 files changed

+19
-20
lines changed

doc/api/http2.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,9 @@ server.on('stream', (stream, headers) => {
23562356
<!-- YAML
23572357
added: v8.4.0
23582358
changes:
2359+
- version: REPLACEME
2360+
pr-url: https://github.com/nodejs/node/pull/29833
2361+
description: The `maxConcurrentStreams` setting is stricter.
23592362
- version: v8.9.3
23602363
pr-url: https://github.com/nodejs/node/pull/16676
23612364
description: The `maxHeaderListSize` setting is now strictly enforced.
@@ -2381,9 +2384,10 @@ properties.
23812384
is 2<sup>24</sup>-1. **Default:** `16,384 bytes`.
23822385
* `maxConcurrentStreams` {number} Specifies the maximum number of concurrent
23832386
streams permitted on an `Http2Session`. There is no default value which
2384-
implies, at least theoretically, 2<sup>31</sup>-1 streams may be open
2387+
implies, at least theoretically, 2<sup>32</sup>-1 streams may be open
23852388
concurrently at any given time in an `Http2Session`. The minimum value
2386-
is 0. The maximum allowed value is 2<sup>31</sup>-1.
2389+
is 0. The maximum allowed value is 2<sup>32</sup>-1. **Default:**
2390+
`4294967295`.
23872391
* `maxHeaderListSize` {number} Specifies the maximum size (uncompressed octets)
23882392
of header list that will be accepted. The minimum allowed value is 0. The
23892393
maximum allowed value is 2<sup>32</sup>-1. **Default:** `65535`.

lib/internal/http2/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function debugSessionObj(session, message, ...args) {
160160

161161
const kMaxFrameSize = (2 ** 24) - 1;
162162
const kMaxInt = (2 ** 32) - 1;
163-
const kMaxStreams = (2 ** 31) - 1;
163+
const kMaxStreams = (2 ** 32) - 1;
164164
const kMaxALTSVC = (2 ** 14) - 2;
165165

166166
// eslint-disable-next-line no-control-regex

src/node_http2.cc

+4
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
289289
DEFAULT_SETTINGS_HEADER_TABLE_SIZE;
290290
buffer[IDX_SETTINGS_ENABLE_PUSH] =
291291
DEFAULT_SETTINGS_ENABLE_PUSH;
292+
buffer[IDX_SETTINGS_MAX_CONCURRENT_STREAMS] =
293+
DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS;
292294
buffer[IDX_SETTINGS_INITIAL_WINDOW_SIZE] =
293295
DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE;
294296
buffer[IDX_SETTINGS_MAX_FRAME_SIZE] =
@@ -298,6 +300,7 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
298300
buffer[IDX_SETTINGS_COUNT] =
299301
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE) |
300302
(1 << IDX_SETTINGS_ENABLE_PUSH) |
303+
(1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS) |
301304
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE) |
302305
(1 << IDX_SETTINGS_MAX_FRAME_SIZE) |
303306
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE);
@@ -3186,6 +3189,7 @@ void Initialize(Local<Object> target,
31863189

31873190
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_HEADER_TABLE_SIZE);
31883191
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_ENABLE_PUSH);
3192+
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS);
31893193
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE);
31903194
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_FRAME_SIZE);
31913195
NODE_DEFINE_CONSTANT(constants, MAX_MAX_FRAME_SIZE);

src/node_http2.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ using performance::PerformanceEntry;
4040
// These are the standard HTTP/2 defaults as specified by the RFC
4141
#define DEFAULT_SETTINGS_HEADER_TABLE_SIZE 4096
4242
#define DEFAULT_SETTINGS_ENABLE_PUSH 1
43+
#define DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS 0xffffffffu
4344
#define DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE 65535
4445
#define DEFAULT_SETTINGS_MAX_FRAME_SIZE 16384
4546
#define DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE 65535

test/parallel/test-http2-binding.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ assert.strictEqual(typeof binding.Http2Session, 'function');
1616
const settings = http2.getDefaultSettings();
1717
assert.strictEqual(settings.headerTableSize, 4096);
1818
assert.strictEqual(settings.enablePush, true);
19+
assert.strictEqual(settings.maxConcurrentStreams, 4294967295);
1920
assert.strictEqual(settings.initialWindowSize, 65535);
2021
assert.strictEqual(settings.maxFrameSize, 16384);
2122

@@ -227,6 +228,7 @@ const expectedNGConstants = {
227228
const defaultSettings = {
228229
DEFAULT_SETTINGS_HEADER_TABLE_SIZE: 4096,
229230
DEFAULT_SETTINGS_ENABLE_PUSH: 1,
231+
DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 4294967295,
230232
DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 65535,
231233
DEFAULT_SETTINGS_MAX_FRAME_SIZE: 16384
232234
};

test/parallel/test-http2-client-setNextStreamID-errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ server.listen(0, common.mustCall(() => {
2626
const client = http2.connect(`http://localhost:${server.address().port}`);
2727

2828
client.on('connect', () => {
29-
const outOfRangeNum = 2 ** 31;
29+
const outOfRangeNum = 2 ** 32;
3030
common.expectsError(
3131
() => client.setNextStreamID(outOfRangeNum),
3232
{
3333
type: RangeError,
3434
code: 'ERR_OUT_OF_RANGE',
3535
message: 'The value of "id" is out of range.' +
36-
' It must be > 0 and <= 2147483647. Received ' + outOfRangeNum
36+
' It must be > 0 and <= 4294967295. Received ' + outOfRangeNum
3737
}
3838
);
3939

test/parallel/test-http2-client-settings-before-connect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ server.listen(0, common.mustCall(() => {
2828
['maxFrameSize', 1, RangeError],
2929
['maxFrameSize', 2 ** 24, RangeError],
3030
['maxConcurrentStreams', -1, RangeError],
31-
['maxConcurrentStreams', 2 ** 31, RangeError],
31+
['maxConcurrentStreams', 2 ** 32, RangeError],
3232
['maxHeaderListSize', -1, RangeError],
3333
['maxHeaderListSize', 2 ** 32, RangeError],
3434
['enablePush', 'a', TypeError],

test/parallel/test-http2-getpackedsettings.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const assert = require('assert');
77
const http2 = require('http2');
88

99
const check = Buffer.from([0x00, 0x01, 0x00, 0x00, 0x10, 0x00,
10+
0x00, 0x03, 0xff, 0xff, 0xff, 0xff,
1011
0x00, 0x05, 0x00, 0x00, 0x40, 0x00,
1112
0x00, 0x04, 0x00, 0x00, 0xff, 0xff,
1213
0x00, 0x06, 0x00, 0x00, 0xff, 0xff,
@@ -41,7 +42,7 @@ http2.getPackedSettings({ enablePush: false });
4142
['maxFrameSize', 16383],
4243
['maxFrameSize', 2 ** 24],
4344
['maxConcurrentStreams', -1],
44-
['maxConcurrentStreams', 2 ** 31],
45+
['maxConcurrentStreams', 2 ** 32],
4546
['maxHeaderListSize', -1],
4647
['maxHeaderListSize', 2 ** 32]
4748
].forEach((i) => {
@@ -168,16 +169,3 @@ http2.getPackedSettings({ enablePush: false });
168169
message: 'Invalid value for setting "maxFrameSize": 16777216'
169170
});
170171
}
171-
172-
// Check for maxConcurrentStreams failing the max number.
173-
{
174-
const packed = Buffer.from([0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]);
175-
176-
common.expectsError(() => {
177-
http2.getUnpackedSettings(packed, { validate: true });
178-
}, {
179-
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
180-
type: RangeError,
181-
message: 'Invalid value for setting "maxConcurrentStreams": 4294967295'
182-
});
183-
}

0 commit comments

Comments
 (0)