]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: collect per-capability stat in proxy_cond_disable()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 12 May 2025 15:12:49 +0000 (17:12 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 2 Jun 2025 15:51:17 +0000 (17:51 +0200)
proxy_cond_disable() collects and prints cumulated connections for be and
fe proxies no matter their type. With shared stats it may cause issues
because depending on the proxy capabilities only fe or be counters may
be allocated.

In this patch we add some checks to ensure we only try to read from
valid memory locations, else we rely on default values (0).

src/proxy.c

index 5ce28274780b9f120dbe3a950df070fe07354cfd..56066bf8e83a056c249f42197d0b4754cf60f924 100644 (file)
@@ -2058,6 +2058,9 @@ void proxy_cond_resume(struct proxy *p)
  */
 void proxy_cond_disable(struct proxy *p)
 {
+       long long cum_conn = 0;
+       long long cum_sess = 0;
+
        if (p->flags & (PR_FL_DISABLED|PR_FL_STOPPED))
                return;
 
@@ -2072,13 +2075,18 @@ 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 = p->fe_counters.cum_conn;
+       if (p->cap & PR_CAP_BE)
+               cum_sess = p->be_counters.cum_sess;
+
        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",
-                          p->id, p->fe_counters.cum_conn, p->be_counters.cum_sess);
+                          p->id, cum_conn, cum_sess);
 
        if ((p->mode == PR_MODE_TCP || p->mode == PR_MODE_HTTP || p->mode == PR_MODE_SPOP) && !(p->cap & PR_CAP_INT))
                send_log(p, LOG_WARNING, "Proxy %s stopped (cumulated conns: FE: %lld, BE: %lld).\n",
-                        p->id, p->fe_counters.cum_conn, p->be_counters.cum_sess);
+                        p->id, cum_conn, cum_sess);
 
        if (p->table && p->table->size && p->table->sync_task)
                task_wakeup(p->table->sync_task, TASK_WOKEN_MSG);