Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit 870ef22

Browse files
committed
Copy rapid reset parameters to the h2 session
This will allow per-session adjustments and also significantly lower the risk of inconsistent calculations in the rate limit code during parameter changes. Ref #3996
1 parent 05a6869 commit 870ef22

4 files changed

Lines changed: 26 additions & 12 deletions

File tree

bin/varnishd/http2/cache_http2.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,13 @@ struct h2_sess {
194194
VTAILQ_HEAD(,h2_req) txqueue;
195195

196196
h2_error error;
197+
198+
// rst rate limit parameters, copied from h2_* parameters
199+
vtim_dur rapid_reset;
200+
int64_t rapid_reset_limit;
201+
vtim_dur rapid_reset_period;
202+
203+
// rst rate limit state
197204
double rst_budget;
198205
vtim_real last_rst;
199206
};

bin/varnishd/http2/cache_http2_proto.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,20 @@ h2_rapid_reset(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
331331
ASSERT_RXTHR(h2);
332332
CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC);
333333

334-
if (cache_param->h2_rapid_reset_limit == 0)
334+
if (h2->rapid_reset_limit == 0)
335335
return (0);
336336

337337
now = VTIM_real();
338338
CHECK_OBJ_NOTNULL(r2->req, REQ_MAGIC);
339339
AN(r2->req->t_first);
340-
if (now - r2->req->t_first > cache_param->h2_rapid_reset)
340+
if (now - r2->req->t_first > h2->rapid_reset)
341341
return (0);
342342

343343
d = now - h2->last_rst;
344-
h2->rst_budget += cache_param->h2_rapid_reset_limit * d /
345-
cache_param->h2_rapid_reset_period;
344+
h2->rst_budget += h2->rapid_reset_limit * d /
345+
h2->rapid_reset_period;
346346
h2->rst_budget = vmin_t(double, h2->rst_budget,
347-
cache_param->h2_rapid_reset_limit);
347+
h2->rapid_reset_limit);
348348
h2->last_rst = now;
349349

350350
if (h2->rst_budget < 1.0) {

bin/varnishd/http2/cache_http2_session.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ h2_init_sess(struct sess *sp,
127127
h2_local_settings(&h2->local_settings);
128128
h2->remote_settings = H2_proto_settings;
129129
h2->decode = decode;
130-
h2->rst_budget = cache_param->h2_rapid_reset_limit;
130+
131+
h2->rapid_reset = cache_param->h2_rapid_reset;
132+
h2->rapid_reset_limit = cache_param->h2_rapid_reset_limit;
133+
h2->rapid_reset_period = cache_param->h2_rapid_reset_period;
134+
135+
h2->rst_budget = h2->rapid_reset_limit;
131136
h2->last_rst = sp->t_open;
132137
AZ(isnan(h2->last_rst));
133138

include/tbl/params.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,8 @@ PARAM_SIMPLE(
12571257
"HTTP2 maximum size of an uncompressed header list."
12581258
)
12591259

1260+
#define H2_RR_INFO \
1261+
"Changes to this parameter affect the default for new HTTP2 sessions"
12601262
PARAM_SIMPLE(
12611263
/* name */ h2_rapid_reset,
12621264
/* typ */ timeout,
@@ -1268,8 +1270,8 @@ PARAM_SIMPLE(
12681270
"The upper threshold for how soon an http/2 RST_STREAM frame has "
12691271
"to be parsed after a HEADERS frame for it to be treated as "
12701272
"suspect and subjected to the rate limits specified by "
1271-
"h2_rapid_reset_limit and h2_rapid_reset_period.",
1272-
/* flags */ EXPERIMENTAL,
1273+
"h2_rapid_reset_limit and h2_rapid_reset_period.\n" H2_RR_INFO,
1274+
/* flags */ EXPERIMENTAL|DELAYED_EFFECT,
12731275
)
12741276

12751277
PARAM_SIMPLE(
@@ -1283,8 +1285,8 @@ PARAM_SIMPLE(
12831285
"HTTP2 RST Allowance.\n"
12841286
"Specifies the maximum number of allowed stream resets issued by\n"
12851287
"a client over a time period before the connection is closed.\n"
1286-
"Setting this parameter to 0 disables the limit.",
1287-
/* flags */ EXPERIMENTAL,
1288+
"Setting this parameter to 0 disables the limit.\n" H2_RR_INFO,
1289+
/* flags */ EXPERIMENTAL|DELAYED_EFFECT,
12881290
)
12891291

12901292
PARAM_SIMPLE(
@@ -1295,8 +1297,8 @@ PARAM_SIMPLE(
12951297
/* def */ "60.000",
12961298
/* units */ "seconds",
12971299
/* descr */
1298-
"HTTP2 sliding window duration for h2_rapid_reset_limit.",
1299-
/* flags */ EXPERIMENTAL|WIZARD,
1300+
"HTTP2 sliding window duration for h2_rapid_reset_limit.\n" H2_RR_INFO,
1301+
/* flags */ EXPERIMENTAL|DELAYED_EFFECT|WIZARD,
13001302
)
13011303

13021304
/*--------------------------------------------------------------------

0 commit comments

Comments
 (0)