]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: connection: "connection:close" header added despite 'close-spread-time'
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Mon, 25 Apr 2022 15:50:48 +0000 (17:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 26 Apr 2022 08:50:47 +0000 (10:50 +0200)
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

index 79fdb553ae6cbbdfac708b98cb89c989302df7be..bdbd61fb19d84f04aa7844f3a4dc545c93b71262 100644 (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))) {
-               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);
+               }
        }
 }