]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: server: initialize the idle conns list after parsing the config
authorWilly Tarreau <w@1wt.eu>
Thu, 7 Feb 2019 13:46:29 +0000 (14:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 7 Feb 2019 14:08:13 +0000 (15:08 +0100)
The idle conns lists are sized according to the number of threads. As such
they cannot be initialized during the parsing since nbthread can be set
later, as revealed by this simple config which randomly crashes when used.
Let's do this at the end instead.

    listen proxy
        bind :4445
        mode http
        timeout client 10s
        timeout server 10s
        timeout connect 10s
        http-reuse always
        server s1 127.0.0.1:8000

    global
        nbthread 8

This fix must be backported to 1.9 and 1.8.

src/cfgparse.c
src/server.c

index 3ed58f39306cacb9be2eb515a06ffb9974c86ca5..44eac17d68cba0c165d06ade7ee2637239abd974 100644 (file)
@@ -3543,6 +3543,31 @@ out_uri_auth_compat:
                        /* update the mux */
                        newsrv->mux_proto = mux_ent;
                }
+
+               /* initialize idle conns lists */
+               for (newsrv = curproxy->srv; newsrv; newsrv = newsrv->next) {
+                       int i;
+
+                       newsrv->priv_conns = calloc(global.nbthread, sizeof(*newsrv->priv_conns));
+                       newsrv->idle_conns = calloc(global.nbthread, sizeof(*newsrv->idle_conns));
+                       newsrv->safe_conns = calloc(global.nbthread, sizeof(*newsrv->safe_conns));
+
+                       if (!newsrv->priv_conns || !newsrv->idle_conns || !newsrv->safe_conns) {
+                               free(srv->safe_conns); srv->safe_conns = NULL;
+                               free(srv->idle_conns); srv->idle_conns = NULL;
+                               free(srv->priv_conns); srv->priv_conns = NULL;
+                               ha_alert("parsing [%s:%d] : failed to allocate idle connections for server '%s'.\n",
+                                        newsrv->conf.file, newsrv->conf.line, newsrv->id);
+                               cfgerr++;
+                               continue;
+                       }
+
+                       for (i = 0; i < global.nbthread; i++) {
+                               LIST_INIT(&newsrv->priv_conns[i]);
+                               LIST_INIT(&newsrv->idle_conns[i]);
+                               LIST_INIT(&newsrv->safe_conns[i]);
+                       }
+               }
        }
 
        /***********************************************************/
index 50325de41ce1a32cab011ee8c1c5f883c907d011..86137f3e5c5c6e25cd368c7cb7442d972613f0e6 100644 (file)
@@ -1713,7 +1713,6 @@ static void srv_settings_cpy(struct server *srv, struct server *src, int srv_tmp
 struct server *new_server(struct proxy *proxy)
 {
        struct server *srv;
-       int i;
 
        srv = calloc(1, sizeof *srv);
        if (!srv)
@@ -1724,19 +1723,6 @@ struct server *new_server(struct proxy *proxy)
        LIST_INIT(&srv->actconns);
        srv->pendconns = EB_ROOT;
 
-       if ((srv->priv_conns = calloc(global.nbthread, sizeof(*srv->priv_conns))) == NULL)
-               goto free_srv;
-       if ((srv->idle_conns = calloc(global.nbthread, sizeof(*srv->idle_conns))) == NULL)
-               goto free_priv_conns;
-       if ((srv->safe_conns = calloc(global.nbthread, sizeof(*srv->safe_conns))) == NULL)
-               goto free_idle_conns;
-
-       for (i = 0; i < global.nbthread; i++) {
-               LIST_INIT(&srv->priv_conns[i]);
-               LIST_INIT(&srv->idle_conns[i]);
-               LIST_INIT(&srv->safe_conns[i]);
-       }
-
        srv->next_state = SRV_ST_RUNNING; /* early server setup */
        srv->last_change = now.tv_sec;
 
@@ -1755,14 +1741,6 @@ struct server *new_server(struct proxy *proxy)
        srv->max_reuse = -1;
 
        return srv;
-
-  free_idle_conns:
-       free(srv->idle_conns);
-  free_priv_conns:
-       free(srv->priv_conns);
-  free_srv:
-       free(srv);
-       return NULL;
 }
 
 /*