]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: proxy: fix crash with stop_proxy() called during init
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 8 Sep 2025 09:01:02 +0000 (11:01 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 8 Sep 2025 11:38:38 +0000 (13:38 +0200)
Willy reported that the following config would segfault right after the
"removing incomplete section 'peer' is emitted:

  peers peers
bind :2300
   server n10 127.0.0.1:2310

  listen dummy
  bind localhost:9999

This is caused by the fact that stop_proxy(), which tries to read shared
counters, is called during early init while shared counters are not yet
initialized. To fix the crash, let's check if we're still during starting
phase, in which case we assume the counters are not initialized and we
assume 0 value instead.

No backport needed unless 16eb0fab31 ("MAJOR: counters: dispatch counters
over thread groups") is.

src/proxy.c

index b2de70bdea877408c1ea45b6ee3fec0d08e0852e..3dda6265bf68187b125e49ac0854c6ee4cdd24dc 100644 (file)
@@ -2137,10 +2137,12 @@ void proxy_cond_disable(struct proxy *p)
         * peers, etc) we must not report them at all as they're not really on
         * the data plane but on the control plane.
         */
-       if (p->cap & PR_CAP_FE)
-               cum_conn = COUNTERS_SHARED_TOTAL(p->fe_counters.shared.tg, cum_conn, HA_ATOMIC_LOAD);
-       if (p->cap & PR_CAP_BE)
-               cum_sess = COUNTERS_SHARED_TOTAL(p->be_counters.shared.tg, cum_sess, HA_ATOMIC_LOAD);
+       if (!(global.mode & MODE_STARTING)) {
+               if (p->cap & PR_CAP_FE)
+                       cum_conn = COUNTERS_SHARED_TOTAL(p->fe_counters.shared.tg, cum_conn, HA_ATOMIC_LOAD);
+               if (p->cap & PR_CAP_BE)
+                       cum_sess = COUNTERS_SHARED_TOTAL(p->be_counters.shared.tg, cum_sess, HA_ATOMIC_LOAD);
+       }
 
        if ((p->mode == PR_MODE_TCP || p->mode == PR_MODE_HTTP || p->mode == PR_MODE_SYSLOG || p->mode == PR_MODE_SPOP) && !(p->cap & PR_CAP_INT))
                ha_warning("Proxy %s stopped (cumulated conns: FE: %lld, BE: %lld).\n",