From: Aurelien DARRAGON Date: Mon, 8 Sep 2025 09:01:02 +0000 (+0200) Subject: BUG/MEDIUM: proxy: fix crash with stop_proxy() called during init X-Git-Tag: v3.3-dev9~201 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9272b8ce7404942f7af563983694937a5e6b7c55;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: proxy: fix crash with stop_proxy() called during init 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. --- diff --git a/src/proxy.c b/src/proxy.c index b2de70bde..3dda6265b 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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",