Skip to content

Commit

Permalink
Copy rapid reset parameters to the h2 session
Browse files Browse the repository at this point in the history
  • Loading branch information
nigoroll committed Oct 16, 2023
1 parent 9ce057c commit 7f99048
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions bin/varnishd/http2/cache_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 stats
double rst_allowance;
vtim_real last_rst;
};
Expand Down
12 changes: 6 additions & 6 deletions bin/varnishd/http2/cache_http2_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,16 @@ 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 == 0 ||
cache_param->h2_rapid_reset_limit == 0)
if (h2->rapid_reset == 0 ||
h2->rapid_reset_limit == 0)
return (0);

now = VTIM_real();
d = now - h2->last_rst;
h2->rst_allowance += (1.0 * d / cache_param->h2_rapid_reset_period) *
cache_param->h2_rapid_reset_limit;
h2->rst_allowance += (1.0 * d / h2->rapid_reset_period) *
h2->rapid_reset_limit;
h2->rst_allowance = vmin_t(double, h2->rst_allowance,
cache_param->h2_rapid_reset_limit);
h2->rapid_reset_limit);
h2->last_rst = now;

if (h2->rst_allowance < 1.0) {
Expand All @@ -354,7 +354,7 @@ h2_rx_rst_stream(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2)
Lck_Unlock(&h2->sess->mtx);
return (H2CE_ENHANCE_YOUR_CALM);
}
if (d < cache_param->h2_rapid_reset)
if (d < h2->rapid_reset)
h2->rst_allowance -= 1.0;

return (0);
Expand Down
7 changes: 6 additions & 1 deletion bin/varnishd/http2/cache_http2_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_allowance = 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_allowance = h2->rapid_reset_limit;
h2->last_rst = sp->t_open;
AZ(isnan(h2->last_rst));

Expand Down

0 comments on commit 7f99048

Please sign in to comment.