From 870e2d3f1f1180391c6d6cd6658c48a76bd91e5a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 19 Jan 2024 17:33:27 +0100 Subject: [PATCH] MEDIUM: mux-h2: update session trackers with number of glitches We now update the session's tracked counters with the observed glitches. In order to avoid incurring a high cost, e.g. if many small frames contain issues, we batch the updates around h2_process_demux() by directly passing the difference. Indeed, for now all functions that increment glitches are called from h2_process_demux(). If that were to change, we'd just need to keep the value of the last synced counter in the h2c struct instead of the stack. The regtest was updated to verify that the 3rd client that does not cause issue still sees the counter resulting from client 2's mistakes. The rate is also verified, considering it shouldn't fail since the period is very long (1m). --- reg-tests/connection/h2_glitches.vtc | 8 +++++++- src/mux_h2.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/reg-tests/connection/h2_glitches.vtc b/reg-tests/connection/h2_glitches.vtc index 39ec4d6852..4f25164d04 100644 --- a/reg-tests/connection/h2_glitches.vtc +++ b/reg-tests/connection/h2_glitches.vtc @@ -11,7 +11,9 @@ haproxy hap -conf { listen fe1 bind "fd@${fe1}" proto h2 - http-request return status 200 hdr x-glitches %[fc_glitches] + tcp-request session track-sc0 src + http-request return status 200 hdr x-glitches %[fc_glitches] hdr x-glitch-cnt %[sc0_glitch_cnt] hdr x-glitch-rate %[sc0_glitch_rate] + stick-table type ip size 10 store glitch_cnt,glitch_rate(1m) } -start # valid request: no glitch @@ -73,6 +75,8 @@ client c2-path -connect ${hap_fe1_sock} { rxresp expect resp.status == 200 expect resp.http.x-glitches == 1 + expect resp.http.x-glitch-cnt == 1 + expect resp.http.x-glitch-rate == 1 } -run } -run @@ -104,5 +108,7 @@ client c3-scheme -connect ${hap_fe1_sock} { rxresp expect resp.status == 200 expect resp.http.x-glitches == 0 + expect resp.http.x-glitch-cnt == 1 + expect resp.http.x-glitch-rate == 1 } -run } -run diff --git a/src/mux_h2.c b/src/mux_h2.c index 4925d8d155..94724a2f9a 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -4364,8 +4364,13 @@ static int h2_process(struct h2c *h2c) if (!(h2c->flags & H2_CF_DEM_BLOCK_ANY) && (b_data(&h2c->dbuf) || (h2c->flags & H2_CF_RCVD_SHUT))) { + int prev_glitches = h2c->glitches; + h2_process_demux(h2c); + if (h2c->glitches != prev_glitches && !(h2c->flags & H2_CF_IS_BACK)) + session_add_glitch_ctr(h2c->conn->owner, h2c->glitches - prev_glitches); + if (h2c->st0 >= H2_CS_ERROR || (h2c->flags & H2_CF_ERROR)) b_reset(&h2c->dbuf);