Skip to content

Commit

Permalink
http2: set default maxConcurrentStreams
Browse files Browse the repository at this point in the history
Set the default maxConcurrentStreams to
NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS.

PR-URL: #29833
Fixes: #29763
Refs: nghttp2/nghttp2@16c4611
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
  • Loading branch information
ZYSzys authored and BridgeAR committed Oct 9, 2019
1 parent a5c2154 commit 3f15378
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
8 changes: 6 additions & 2 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,9 @@ server.on('stream', (stream, headers) => {
<!-- YAML
added: v8.4.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/29833
description: The `maxConcurrentStreams` setting is stricter.
- version: v8.9.3
pr-url: https://github.com/nodejs/node/pull/16676
description: The `maxHeaderListSize` setting is now strictly enforced.
Expand All @@ -2382,9 +2385,10 @@ properties.
is 2<sup>24</sup>-1. **Default:** `16,384 bytes`.
* `maxConcurrentStreams` {number} Specifies the maximum number of concurrent
streams permitted on an `Http2Session`. There is no default value which
implies, at least theoretically, 2<sup>31</sup>-1 streams may be open
implies, at least theoretically, 2<sup>32</sup>-1 streams may be open
concurrently at any given time in an `Http2Session`. The minimum value
is 0. The maximum allowed value is 2<sup>31</sup>-1.
is 0. The maximum allowed value is 2<sup>32</sup>-1. **Default:**
`4294967295`.
* `maxHeaderListSize` {number} Specifies the maximum size (uncompressed octets)
of header list that will be accepted. The minimum allowed value is 0. The
maximum allowed value is 2<sup>32</sup>-1. **Default:** `65535`.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ function debugSessionObj(session, message, ...args) {

const kMaxFrameSize = (2 ** 24) - 1;
const kMaxInt = (2 ** 32) - 1;
const kMaxStreams = (2 ** 31) - 1;
const kMaxStreams = (2 ** 32) - 1;
const kMaxALTSVC = (2 ** 14) - 2;

// eslint-disable-next-line no-control-regex
Expand Down
4 changes: 4 additions & 0 deletions src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
DEFAULT_SETTINGS_HEADER_TABLE_SIZE;
buffer[IDX_SETTINGS_ENABLE_PUSH] =
DEFAULT_SETTINGS_ENABLE_PUSH;
buffer[IDX_SETTINGS_MAX_CONCURRENT_STREAMS] =
DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS;
buffer[IDX_SETTINGS_INITIAL_WINDOW_SIZE] =
DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE;
buffer[IDX_SETTINGS_MAX_FRAME_SIZE] =
Expand All @@ -301,6 +303,7 @@ void Http2Session::Http2Settings::RefreshDefaults(Environment* env) {
buffer[IDX_SETTINGS_COUNT] =
(1 << IDX_SETTINGS_HEADER_TABLE_SIZE) |
(1 << IDX_SETTINGS_ENABLE_PUSH) |
(1 << IDX_SETTINGS_MAX_CONCURRENT_STREAMS) |
(1 << IDX_SETTINGS_INITIAL_WINDOW_SIZE) |
(1 << IDX_SETTINGS_MAX_FRAME_SIZE) |
(1 << IDX_SETTINGS_MAX_HEADER_LIST_SIZE);
Expand Down Expand Up @@ -3233,6 +3236,7 @@ void Initialize(Local<Object> target,

NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_HEADER_TABLE_SIZE);
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_ENABLE_PUSH);
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS);
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE);
NODE_DEFINE_CONSTANT(constants, DEFAULT_SETTINGS_MAX_FRAME_SIZE);
NODE_DEFINE_CONSTANT(constants, MAX_MAX_FRAME_SIZE);
Expand Down
1 change: 1 addition & 0 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ using performance::PerformanceEntry;
// These are the standard HTTP/2 defaults as specified by the RFC
#define DEFAULT_SETTINGS_HEADER_TABLE_SIZE 4096
#define DEFAULT_SETTINGS_ENABLE_PUSH 1
#define DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS 0xffffffffu
#define DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE 65535
#define DEFAULT_SETTINGS_MAX_FRAME_SIZE 16384
#define DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE 65535
Expand Down
2 changes: 2 additions & 0 deletions test/parallel/test-http2-binding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ assert.strictEqual(typeof binding.Http2Session, 'function');
const settings = http2.getDefaultSettings();
assert.strictEqual(settings.headerTableSize, 4096);
assert.strictEqual(settings.enablePush, true);
assert.strictEqual(settings.maxConcurrentStreams, 4294967295);
assert.strictEqual(settings.initialWindowSize, 65535);
assert.strictEqual(settings.maxFrameSize, 16384);

Expand Down Expand Up @@ -227,6 +228,7 @@ const expectedNGConstants = {
const defaultSettings = {
DEFAULT_SETTINGS_HEADER_TABLE_SIZE: 4096,
DEFAULT_SETTINGS_ENABLE_PUSH: 1,
DEFAULT_SETTINGS_MAX_CONCURRENT_STREAMS: 4294967295,
DEFAULT_SETTINGS_INITIAL_WINDOW_SIZE: 65535,
DEFAULT_SETTINGS_MAX_FRAME_SIZE: 16384
};
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-http2-client-setNextStreamID-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ server.listen(0, common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);

client.on('connect', () => {
const outOfRangeNum = 2 ** 31;
const outOfRangeNum = 2 ** 32;
common.expectsError(
() => client.setNextStreamID(outOfRangeNum),
{
type: RangeError,
code: 'ERR_OUT_OF_RANGE',
message: 'The value of "id" is out of range.' +
' It must be > 0 and <= 2147483647. Received ' + outOfRangeNum
' It must be > 0 and <= 4294967295. Received ' + outOfRangeNum
}
);

Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-http2-client-settings-before-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ server.listen(0, common.mustCall(() => {
['maxFrameSize', 1, RangeError],
['maxFrameSize', 2 ** 24, RangeError],
['maxConcurrentStreams', -1, RangeError],
['maxConcurrentStreams', 2 ** 31, RangeError],
['maxConcurrentStreams', 2 ** 32, RangeError],
['maxHeaderListSize', -1, RangeError],
['maxHeaderListSize', 2 ** 32, RangeError],
['enablePush', 'a', TypeError],
Expand Down
16 changes: 2 additions & 14 deletions test/parallel/test-http2-getpackedsettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const assert = require('assert');
const http2 = require('http2');

const check = Buffer.from([0x00, 0x01, 0x00, 0x00, 0x10, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff,
0x00, 0x05, 0x00, 0x00, 0x40, 0x00,
0x00, 0x04, 0x00, 0x00, 0xff, 0xff,
0x00, 0x06, 0x00, 0x00, 0xff, 0xff,
Expand Down Expand Up @@ -41,7 +42,7 @@ http2.getPackedSettings({ enablePush: false });
['maxFrameSize', 16383],
['maxFrameSize', 2 ** 24],
['maxConcurrentStreams', -1],
['maxConcurrentStreams', 2 ** 31],
['maxConcurrentStreams', 2 ** 32],
['maxHeaderListSize', -1],
['maxHeaderListSize', 2 ** 32]
].forEach((i) => {
Expand Down Expand Up @@ -168,16 +169,3 @@ http2.getPackedSettings({ enablePush: false });
message: 'Invalid value for setting "maxFrameSize": 16777216'
});
}

// Check for maxConcurrentStreams failing the max number.
{
const packed = Buffer.from([0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF]);

common.expectsError(() => {
http2.getUnpackedSettings(packed, { validate: true });
}, {
code: 'ERR_HTTP2_INVALID_SETTING_VALUE',
type: RangeError,
message: 'Invalid value for setting "maxConcurrentStreams": 4294967295'
});
}

0 comments on commit 3f15378

Please sign in to comment.