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.
This commit is contained in:
Remi Tricot-Le Breton 2022-04-25 17:50:48 +02:00 committed by Christopher Faulet
parent acef5e27b0
commit b4f5fac886

View File

@ -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))) { 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; int want_clo = 1;
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); /* 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);
}
} }
} }