]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: handle shared listener counters preparation from proxy_postcheck()
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 8 Aug 2025 12:56:18 +0000 (14:56 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Wed, 27 Aug 2025 10:54:25 +0000 (12:54 +0200)
We used to allocate and prepare listener counters from
check_config_validity() all at once. But it isn't correct, since at that
time listeners's guid are not inserted yet, thus
counters_fe_shared_prepare() cannot work correctly, and so does
shm_stats_file_preload() which is meant to be called even earlier.

Thus in this commit (and to prepare for upcoming shm shared counters
preloading patches), we handle the shared listener counters prep in
proxy_postcheck(), which means that between the allocation and the
prep there is the proper window for listener's guid insertion and shm
counters preloading.

No change of behavior expected when shm shared counters are not
actually used.

src/cfgparse.c
src/proxy.c

index 34412311513ccebf2410b6062e9ffc3231aeeb04..3880549b8ec4b2451c74e7af531fdd355cda70b8 100644 (file)
@@ -4279,14 +4279,6 @@ init_proxies_list_stage2:
                        /* enable separate counters */
                        if (curproxy->options2 & PR_O2_SOCKSTAT) {
                                listener->counters = calloc(1, sizeof(*listener->counters));
-                               if (listener->counters) {
-                                       if (!counters_fe_shared_prepare(&listener->counters->shared, &listener->guid)) {
-                                               ha_free(&listener->counters);
-                                               ha_alert("config: %s '%s': out of memory.\n",
-                                                        proxy_type_str(curproxy), curproxy->id);
-                                       }
-
-                               }
                                if (!listener->name)
                                        memprintf(&listener->name, "sock-%d", listener->luid);
                        }
index 2bcd87f6f235c09309ac24f07839a9cfdd65e35f..028d2ac149ff32f29209d78d7e5e3f20ecae1062 100644 (file)
@@ -1748,6 +1748,7 @@ struct proxy *alloc_new_proxy(const char *name, unsigned int cap, char **errmsg)
 /* post-check for proxies */
 static int proxy_postcheck(struct proxy *px)
 {
+       struct listener *listener;
        int err_code = ERR_NONE;
 
        /* allocate private memory for shared counters: used as a fallback
@@ -1777,6 +1778,17 @@ static int proxy_postcheck(struct proxy *px)
 
        }
 
+       list_for_each_entry(listener, &px->conf.listeners, by_fe) {
+               if (listener->counters) {
+                       if (!counters_fe_shared_prepare(&listener->counters->shared, &listener->guid)) {
+                               ha_free(&listener->counters);
+                               ha_alert("out of memory while setting up shared listener counters for %s %s\n",
+                                        proxy_type_str(px), px->id);
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
+               }
+       }
 
  out:
        return err_code;