]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: servers: Move the per-thread server initialization earlier
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 17 Apr 2025 08:42:25 +0000 (10:42 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 17 Apr 2025 15:38:23 +0000 (17:38 +0200)
Move the code responsible for calling per-thread server initialization
earlier than it was done, so that per-thread structures are available a
bit later, when we initialize load-balancing.

src/cfgparse.c

index b91da359fc8befc33f74908a3d7d3f953df686ab..d1c850cdc1554e676cf969d221cd03854af203f1 100644 (file)
@@ -2789,6 +2789,32 @@ int check_config_validity()
                proxies_list = next;
        }
 
+       /*
+        * we must finish to initialize certain things on the servers,
+        * as some of the per_thr/per_tgrp fields may be accessed soon
+        */
+
+       MT_LIST_FOR_EACH_ENTRY_LOCKED(newsrv, &servers_list, global_list, back) {
+               if (srv_init_per_thr(newsrv) == -1) {
+                       ha_alert("parsing [%s:%d] : failed to allocate per-thread lists for server '%s'.\n",
+                                newsrv->conf.file, newsrv->conf.line, newsrv->id);
+                       cfgerr++;
+                       continue;
+               }
+
+               /* initialize idle conns lists */
+               if (newsrv->max_idle_conns != 0) {
+                       newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
+                       if (!newsrv->curr_idle_thr) {
+                               ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
+                                        newsrv->conf.file, newsrv->conf.line, newsrv->id);
+                               cfgerr++;
+                               continue;
+                       }
+
+               }
+       }
+
        /* starting to initialize the main proxies list */
        init_proxies_list = proxies_list;
 
@@ -4142,29 +4168,6 @@ out_uri_auth_compat:
        /* At this point, target names have already been resolved. */
        /***********************************************************/
 
-       /* we must finish to initialize certain things on the servers */
-
-       MT_LIST_FOR_EACH_ENTRY_LOCKED(newsrv, &servers_list, global_list, back) {
-               /* initialize idle conns lists */
-               if (srv_init_per_thr(newsrv) == -1) {
-                       ha_alert("parsing [%s:%d] : failed to allocate per-thread lists for server '%s'.\n",
-                                newsrv->conf.file, newsrv->conf.line, newsrv->id);
-                       cfgerr++;
-                       continue;
-               }
-
-               if (newsrv->max_idle_conns != 0) {
-                       newsrv->curr_idle_thr = calloc(global.nbthread, sizeof(*newsrv->curr_idle_thr));
-                       if (!newsrv->curr_idle_thr) {
-                               ha_alert("parsing [%s:%d] : failed to allocate idle connection tasks for server '%s'.\n",
-                                        newsrv->conf.file, newsrv->conf.line, newsrv->id);
-                               cfgerr++;
-                               continue;
-                       }
-
-               }
-       }
-
        idle_conn_task = task_new_anywhere();
        if (!idle_conn_task) {
                ha_alert("parsing : failed to allocate global idle connection task.\n");