[7.4] e12a088c4 Copy rapid reset parameters to the h2 session

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Oct 23 17:18:10 UTC 2023


commit e12a088c44ed68586b67c530eed89469ed0da2a7
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Oct 17 13:47:39 2023 +0200

    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

diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h
index 65ea1d2df..ca2e65993 100644
--- a/bin/varnishd/http2/cache_http2.h
+++ b/bin/varnishd/http2/cache_http2.h
@@ -194,6 +194,13 @@ struct h2_sess {
 	VTAILQ_HEAD(,h2_req)		txqueue;
 
 	h2_error			error;
+
+	// rst rate limit parameters, copied from h2_* parameters
+	vtim_dur			rapid_reset;
+	int64_t				rapid_reset_limit;
+	vtim_dur			rapid_reset_period;
+
+	// rst rate limit state
 	double				rst_budget;
 	vtim_real			last_rst;
 };
diff --git a/bin/varnishd/http2/cache_http2_proto.c b/bin/varnishd/http2/cache_http2_proto.c
index 50504c021..edcc709d9 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -331,20 +331,20 @@ h2_rapid_reset(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
 	ASSERT_RXTHR(h2);
 	CHECK_OBJ_NOTNULL(r2, H2_REQ_MAGIC);
 
-	if (cache_param->h2_rapid_reset_limit == 0)
+	if (h2->rapid_reset_limit == 0)
 		return (0);
 
 	now = VTIM_real();
 	CHECK_OBJ_NOTNULL(r2->req, REQ_MAGIC);
 	AN(r2->req->t_first);
-	if (now - r2->req->t_first > cache_param->h2_rapid_reset)
+	if (now - r2->req->t_first > h2->rapid_reset)
 		return (0);
 
 	d = now - h2->last_rst;
-	h2->rst_budget += cache_param->h2_rapid_reset_limit * d /
-	    cache_param->h2_rapid_reset_period;
+	h2->rst_budget += h2->rapid_reset_limit * d /
+	    h2->rapid_reset_period;
 	h2->rst_budget = vmin_t(double, h2->rst_budget,
-	    cache_param->h2_rapid_reset_limit);
+	    h2->rapid_reset_limit);
 	h2->last_rst = now;
 
 	if (h2->rst_budget < 1.0) {
diff --git a/bin/varnishd/http2/cache_http2_session.c b/bin/varnishd/http2/cache_http2_session.c
index ef0d88ede..acbfdbb51 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -127,7 +127,12 @@ h2_init_sess(struct sess *sp,
 	h2_local_settings(&h2->local_settings);
 	h2->remote_settings = H2_proto_settings;
 	h2->decode = decode;
-	h2->rst_budget = cache_param->h2_rapid_reset_limit;
+
+	h2->rapid_reset = cache_param->h2_rapid_reset;
+	h2->rapid_reset_limit = cache_param->h2_rapid_reset_limit;
+	h2->rapid_reset_period = cache_param->h2_rapid_reset_period;
+
+	h2->rst_budget = h2->rapid_reset_limit;
 	h2->last_rst = sp->t_open;
 	AZ(isnan(h2->last_rst));
 
diff --git a/include/tbl/params.h b/include/tbl/params.h
index ae622e53d..003f08d2a 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1257,6 +1257,8 @@ PARAM_SIMPLE(
 	"HTTP2 maximum size of an uncompressed header list."
 )
 
+#define H2_RR_INFO \
+	"Changes to this parameter affect the default for new HTTP2 sessions"
 PARAM_SIMPLE(
 	/* name */	h2_rapid_reset,
 	/* typ */	timeout,
@@ -1268,8 +1270,8 @@ PARAM_SIMPLE(
 	"The upper threshold for how soon an http/2 RST_STREAM frame has "
 	"to be parsed after a HEADERS frame for it to be treated as "
 	"suspect and subjected to the rate limits specified by "
-	"h2_rapid_reset_limit and h2_rapid_reset_period.",
-	/* flags */	EXPERIMENTAL,
+	"h2_rapid_reset_limit and h2_rapid_reset_period.\n" H2_RR_INFO,
+	/* flags */	EXPERIMENTAL|DELAYED_EFFECT,
 )
 
 PARAM_SIMPLE(
@@ -1283,8 +1285,8 @@ PARAM_SIMPLE(
 	"HTTP2 RST Allowance.\n"
 	"Specifies the maximum number of allowed stream resets issued by\n"
 	"a client over a time period before the connection is closed.\n"
-	"Setting this parameter to 0 disables the limit.",
-	/* flags */	EXPERIMENTAL,
+	"Setting this parameter to 0 disables the limit.\n" H2_RR_INFO,
+	/* flags */	EXPERIMENTAL|DELAYED_EFFECT,
 )
 
 PARAM_SIMPLE(
@@ -1295,8 +1297,8 @@ PARAM_SIMPLE(
 	/* def */	"60.000",
 	/* units */	"seconds",
 	/* descr */
-	"HTTP2 sliding window duration for h2_rapid_reset_limit.",
-	/* flags */	EXPERIMENTAL|WIZARD,
+	"HTTP2 sliding window duration for h2_rapid_reset_limit.\n" H2_RR_INFO,
+	/* flags */	EXPERIMENTAL|DELAYED_EFFECT|WIZARD,
 )
 
 /*--------------------------------------------------------------------


More information about the varnish-commit mailing list