Skip to content

Commit e543254

Browse files
committed
http2: expose nghttp2_option_set_stream_reset_rate_limit as an option
1 parent a1a3caf commit e543254

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

doc/api/http2.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,9 @@ Throws `ERR_INVALID_ARG_TYPE` for invalid `settings` argument.
27662766
<!-- YAML
27672767
added: v8.4.0
27682768
changes:
2769+
- version:
2770+
- REPLACEME
2771+
description: Added `streamResetBurst` and `streamResetRate`.
27692772
- version:
27702773
- v15.10.0
27712774
- v14.16.0
@@ -2868,6 +2871,9 @@ changes:
28682871
**Default:** `100`.
28692872
* `settings` {HTTP/2 Settings Object} The initial settings to send to the
28702873
remote peer upon connection.
2874+
* `streamResetBurst` {number} and `streamResetRate` {number} Sets the rate
2875+
limit for the incoming stream reset (RST_STREAM frame). Both settings must
2876+
be set to have any effect, and default to 1000 and 33 respectively.
28712877
* `remoteCustomSettings` {Array} The array of integer values determines the
28722878
settings types, which are included in the `CustomSettings`-property of
28732879
the received remoteSettings. Please see the `CustomSettings`-property of

lib/internal/http2/util.js

Lines changed: 13 additions & 1 deletion
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.streamResetBurstLimit === '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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const Http2Session::Callbacks Http2Session::callback_struct_saved[2] = {
7979
// When the Http2Scope passes out of scope and is deconstructed, it will
8080
// call Http2Session::MaybeScheduleWrite().
8181
Http2Scope::Http2Scope(Http2Stream* stream) : Http2Scope(stream->session()) {}
82-
82+
#include <iostream>
8383
Http2Scope::Http2Scope(Http2Session* session) : session_(session) {
8484
if (!session_) return;
8585

@@ -208,6 +208,13 @@ 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)) && (flags & (1 << IDX_OPTIONS_STREAM_RESET_RATE))) {
213+
nghttp2_option_set_stream_reset_rate_limit(
214+
option,
215+
static_cast<uint64_t>(buffer[IDX_OPTIONS_STREAM_RESET_BURST]),
216+
static_cast<uint64_t>(buffer[IDX_OPTIONS_STREAM_RESET_RATE]));
217+
}
211218
}
212219

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

src/node_http2_state.h

Lines changed: 2 additions & 0 deletions
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

Lines changed: 9 additions & 1 deletion
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)