From b4f5fac886e83bf4d0cfef6d2b167f87bbd0b7e8 Mon Sep 17 00:00:00 2001 From: Remi Tricot-Le Breton Date: Mon, 25 Apr 2022 17:50:48 +0200 Subject: [PATCH] BUG/MINOR: connection: "connection:close" header added despite 'close-spread-time' Despite what the 'close-spread-time' option should do, the 'connection:close' header was always added to HTTP responses during soft-stops even with a soft-stop window defined. This patch adds the proper random based closing to HTTP connections during a soft-stop (based on the time left in the soft close window). It should be backported to 2.5 once 'MEDIUM: global: Add a "close-spread-time" option to spread soft-stop on time window' is backported as well. --- src/mux_h1.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/mux_h1.c b/src/mux_h1.c index 79fdb553a..bdbd61fb1 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -1197,10 +1197,29 @@ static void h1_set_cli_conn_mode(struct h1s *h1s, struct h1m *h1m) } } - /* If KAL, check if the frontend is stopping. If yes, switch in CLO mode */ + /* If KAL, check if the frontend is stopping. If yes, switch in CLO mode + * unless a 'close-spread-time' option is set. + */ if (h1s->flags & H1S_F_WANT_KAL && (fe->flags & (PR_FL_DISABLED|PR_FL_STOPPED))) { - h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO; - TRACE_STATE("stopping, set close mode", H1_EV_RX_DATA|H1_EV_RX_HDRS|H1_EV_TX_DATA|H1_EV_TX_HDRS, h1s->h1c->conn, h1s); + int want_clo = 1; + /* If a close-spread-time option is set, we want to avoid + * closing all the active HTTP connections at once so we add a + * random factor that will spread the closing. + */ + if (tick_isset(global.close_spread_end)) { + int remaining_window = tick_remain(now_ms, global.close_spread_end); + if (remaining_window) { + /* This should increase the closing rate the further along + * the window we are. + */ + want_clo = (remaining_window <= statistical_prng_range(global.close_spread_time)); + } + } + + if (want_clo) { + h1s->flags = (h1s->flags & ~H1S_F_WANT_MSK) | H1S_F_WANT_CLO; + TRACE_STATE("stopping, set close mode", H1_EV_RX_DATA|H1_EV_RX_HDRS|H1_EV_TX_DATA|H1_EV_TX_HDRS, h1s->h1c->conn, h1s); + } } }