[6.0] bdf0c89bd Copy rapid reset parameters to the h2 session

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Oct 18 16:40:08 UTC 2023


commit bdf0c89bd05f6017345d094e5aa20c5bcf4e5a44
Author: Dag Haavi Finstad <daghf at varnish-software.com>
Date:   Wed Oct 18 14:32:32 2023 +0200

    Copy rapid reset parameters to the h2 session
    
    backport of f820f8016193d0aadbd8b2a52ff241a3145686f4
    
    Conflicts:
            include/tbl/params.h

diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h
index 8fa1da610..4020b2887 100644
--- a/bin/varnishd/http2/cache_http2.h
+++ b/bin/varnishd/http2/cache_http2.h
@@ -192,8 +192,14 @@ struct h2_sess {
 	VTAILQ_HEAD(,h2_req)		txqueue;
 
 	h2_error			error;
-
 	int				open_streams;
+
+	// 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 e6ac6a6c4..afa9f03ef 100644
--- a/bin/varnishd/http2/cache_http2_proto.c
+++ b/bin/varnishd/http2/cache_http2_proto.c
@@ -325,20 +325,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 b45b6e3ac..06e625f33 100644
--- a/bin/varnishd/http2/cache_http2_session.c
+++ b/bin/varnishd/http2/cache_http2_session.c
@@ -127,7 +127,12 @@ h2_init_sess(const struct worker *wrk, 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 7b778820d..665303db4 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1896,6 +1896,10 @@ PARAM(
 )
 #endif
 
+#define H2_RR_INFO \
+	"Changes to this parameter affect the default for new HTTP2 " \
+	"sessions."
+
 PARAM(
 	/* name */	h2_rapid_reset,
 	/* typ */	timeout,
@@ -1903,12 +1907,12 @@ PARAM(
 	/* max */	NULL,
 	/* default */	"1.0",
 	/* units */	"seconds",
-	/* flags */	EXPERIMENTAL,
+	/* flags */	EXPERIMENTAL | DELAYED_EFFECT,
 	/* s-text */
 	"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.",
+	"h2_rapid_reset_limit and h2_rapid_reset_period." H2_RR_INFO,
 	/* l-text */	"",
 	/* func */	NULL
 )
@@ -1921,12 +1925,12 @@ PARAM(
 	/* max */	NULL,
 	/* default */	"100",
 	/* units */	NULL,
-	/* flags */	EXPERIMENTAL,
+	/* flags */	EXPERIMENTAL | DELAYED_EFFECT,
 	/* s-text */
 	"HTTP2 RST Allowance.\n\n"
 	"Specifies the maximum number of allowed stream resets issued by "
 	"a client over a time period before the connection is closed. Setting "
-	"this parameter to 0 disables the limit.",
+	"this parameter to 0 disables the limit." H2_RR_INFO,
 	/* l-text */	"",
 	/* func */	NULL
 )
@@ -1939,9 +1943,9 @@ PARAM(
 	/* max */	NULL,
 	/* default */	"60.000",
 	/* units */	"seconds",
-	/* flags */	EXPERIMENTAL|WIZARD,
+	/* flags */	EXPERIMENTAL | DELAYED_EFFECT | WIZARD,
 	/* s-text */
-	"HTTP2 sliding window duration for h2_rapid_reset_limit.",
+	"HTTP2 sliding window duration for h2_rapid_reset_limit." H2_RR_INFO,
 	/* l-text */	"",
 	/* func */	NULL
 )


More information about the varnish-commit mailing list