From ec0d9380b08058049362c742ee8ee8207c0342bb Mon Sep 17 00:00:00 2001 From: Nils Goroll Date: Tue, 17 Oct 2023 13:47:39 +0200 Subject: [PATCH] Copy rapid reset parameters to the h2 session Ref #3996 --- bin/varnishd/http2/cache_http2.h | 7 +++++++ bin/varnishd/http2/cache_http2_proto.c | 10 +++++----- bin/varnishd/http2/cache_http2_session.c | 7 ++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h index 9457c99f2dd..1fcdb981008 100644 --- a/bin/varnishd/http2/cache_http2.h +++ b/bin/varnishd/http2/cache_http2.h @@ -193,6 +193,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 3367435b860..8585cebb0ac 100644 --- a/bin/varnishd/http2/cache_http2_proto.c +++ b/bin/varnishd/http2/cache_http2_proto.c @@ -337,20 +337,20 @@ h2_rx_rst_stream(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2) return (0); h2_kill_req(wrk, h2, r2, h2_streamerror(vbe32dec(h2->rxf_data))); - 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 672b40d6435..c96c3783211 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));