Skip to content

Commit 914db60

Browse files
arcanistargos
authored andcommitted
http2: expose nghttp2_option_set_stream_reset_rate_limit as an option
PR-URL: #54875 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
1 parent 781ffd8 commit 914db60

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

doc/api/http2.md

+7
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,10 @@ Throws `ERR_INVALID_ARG_TYPE` for invalid `settings` argument.
27662766
<!-- YAML
27672767
added: v8.4.0
27682768
changes:
2769+
- version:
2770+
- REPLACEME
2771+
pr-url: https://github.com/nodejs/node/pull/54875
2772+
description: Added `streamResetBurst` and `streamResetRate`.
27692773
- version:
27702774
- v15.10.0
27712775
- v14.16.0
@@ -2868,6 +2872,9 @@ changes:
28682872
**Default:** `100`.
28692873
* `settings` {HTTP/2 Settings Object} The initial settings to send to the
28702874
remote peer upon connection.
2875+
* `streamResetBurst` {number} and `streamResetRate` {number} Sets the rate
2876+
limit for the incoming stream reset (RST\_STREAM frame). Both settings must
2877+
be set to have any effect, and default to 1000 and 33 respectively.
28712878
* `remoteCustomSettings` {Array} The array of integer values determines the
28722879
settings types, which are included in the `CustomSettings`-property of
28732880
the received remoteSettings. Please see the `CustomSettings`-property of

lib/internal/http2/util.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ const IDX_OPTIONS_MAX_OUTSTANDING_PINGS = 6;
216216
const IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS = 7;
217217
const IDX_OPTIONS_MAX_SESSION_MEMORY = 8;
218218
const IDX_OPTIONS_MAX_SETTINGS = 9;
219-
const IDX_OPTIONS_FLAGS = 10;
219+
const IDX_OPTIONS_STREAM_RESET_RATE = 10;
220+
const IDX_OPTIONS_STREAM_RESET_BURST = 11;
221+
const IDX_OPTIONS_FLAGS = 12;
220222

221223
function updateOptionsBuffer(options) {
222224
let flags = 0;
@@ -270,6 +272,16 @@ function updateOptionsBuffer(options) {
270272
optionsBuffer[IDX_OPTIONS_MAX_SETTINGS] =
271273
MathMax(1, options.maxSettings);
272274
}
275+
if (typeof options.streamResetRate === 'number') {
276+
flags |= (1 << IDX_OPTIONS_STREAM_RESET_RATE);
277+
optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE] =
278+
MathMax(1, options.streamResetRate);
279+
}
280+
if (typeof options.streamResetBurst === 'number') {
281+
flags |= (1 << IDX_OPTIONS_STREAM_RESET_BURST);
282+
optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST] =
283+
MathMax(1, options.streamResetBurst);
284+
}
273285
optionsBuffer[IDX_OPTIONS_FLAGS] = flags;
274286
}
275287

src/node_http2.cc

+8
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ Http2Options::Http2Options(Http2State* http2_state, SessionType type) {
208208
option,
209209
static_cast<size_t>(buffer[IDX_OPTIONS_MAX_SETTINGS]));
210210
}
211+
212+
if ((flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST)) &&
213+
(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE))) {
214+
nghttp2_option_set_stream_reset_rate_limit(
215+
option,
216+
static_cast<uint64_t>(buffer[IDX_OPTIONS_STREAM_RESET_BURST]),
217+
static_cast<uint64_t>(buffer[IDX_OPTIONS_STREAM_RESET_RATE]));
218+
}
211219
}
212220

213221
#define GRABSETTING(entries, count, name) \

src/node_http2_state.h

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace http2 {
5858
IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS,
5959
IDX_OPTIONS_MAX_SESSION_MEMORY,
6060
IDX_OPTIONS_MAX_SETTINGS,
61+
IDX_OPTIONS_STREAM_RESET_RATE,
62+
IDX_OPTIONS_STREAM_RESET_BURST,
6163
IDX_OPTIONS_FLAGS
6264
};
6365

test/parallel/test-http2-util-update-options-buffer.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ const IDX_OPTIONS_MAX_OUTSTANDING_PINGS = 6;
2323
const IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS = 7;
2424
const IDX_OPTIONS_MAX_SESSION_MEMORY = 8;
2525
const IDX_OPTIONS_MAX_SETTINGS = 9;
26-
const IDX_OPTIONS_FLAGS = 10;
26+
const IDX_OPTIONS_STREAM_RESET_RATE = 10;
27+
const IDX_OPTIONS_STREAM_RESET_BURST = 11;
28+
const IDX_OPTIONS_FLAGS = 12;
2729

2830
{
2931
updateOptionsBuffer({
@@ -37,6 +39,8 @@ const IDX_OPTIONS_FLAGS = 10;
3739
maxOutstandingSettings: 8,
3840
maxSessionMemory: 9,
3941
maxSettings: 10,
42+
streamResetRate: 11,
43+
streamResetBurst: 12,
4044
});
4145

4246
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_DEFLATE_DYNAMIC_TABLE_SIZE], 1);
@@ -49,6 +53,8 @@ const IDX_OPTIONS_FLAGS = 10;
4953
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS], 8);
5054
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SESSION_MEMORY], 9);
5155
strictEqual(optionsBuffer[IDX_OPTIONS_MAX_SETTINGS], 10);
56+
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_RATE], 11);
57+
strictEqual(optionsBuffer[IDX_OPTIONS_STREAM_RESET_BURST], 12);
5258

5359
const flags = optionsBuffer[IDX_OPTIONS_FLAGS];
5460

@@ -61,6 +67,8 @@ const IDX_OPTIONS_FLAGS = 10;
6167
ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_PINGS));
6268
ok(flags & (1 << IDX_OPTIONS_MAX_OUTSTANDING_SETTINGS));
6369
ok(flags & (1 << IDX_OPTIONS_MAX_SETTINGS));
70+
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE));
71+
ok(flags & (1 << IDX_OPTIONS_STREAM_RESET_BURST));
6472
}
6573

6674
{

0 commit comments

Comments
 (0)