MINOR: check: do not increment global maxsock at runtime
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 29 Jul 2021 13:39:43 +0000 (15:39 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Fri, 6 Aug 2021 09:08:24 +0000 (11:08 +0200)
global maxsock is used to estimate a number of fd to reserve for
internal use, such as checks. It is incremented at startup with the info
from the config file.

Disable this incrementation in checks functions at runtime. First, it
currently serves no purpose to increment it after startup. Worse, it may
lead to out-of-bound accesse on the fdtab.

This will be useful to initiate checks for dynamic servers.

src/check.c

index 1391d11..c2ab8e8 100644 (file)
@@ -1647,7 +1647,13 @@ int init_srv_check(struct server *srv)
                goto out;
        }
        srv->check.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED;
-       global.maxsock++;
+
+       /* Only increment maxsock for servers from the configuration. Dynamic
+        * servers at the moment are not taken into account for the estimation
+        * of the resources limits.
+        */
+       if (global.mode & MODE_STARTING)
+               global.maxsock++;
 
   out:
        return ret;
@@ -1696,7 +1702,13 @@ int init_srv_agent_check(struct server *srv)
                srv->agent.inter = srv->check.inter;
 
        srv->agent.state |= CHK_ST_CONFIGURED | CHK_ST_ENABLED | CHK_ST_AGENT;
-       global.maxsock++;
+
+       /* Only increment maxsock for servers from the configuration. Dynamic
+        * servers at the moment are not taken into account for the estimation
+        * of the resources limits.
+        */
+       if (global.mode & MODE_STARTING)
+               global.maxsock++;
 
   out:
        return ret;
@@ -1937,7 +1949,13 @@ static int srv_parse_agent_port(char **args, int *cur_arg, struct proxy *curpx,
                goto error;
        }
 
-       global.maxsock++;
+       /* Only increment maxsock for servers from the configuration. Dynamic
+        * servers at the moment are not taken into account for the estimation
+        * of the resources limits.
+        */
+       if (global.mode & MODE_STARTING)
+               global.maxsock++;
+
        set_srv_agent_port(srv, atol(args[*cur_arg + 1]));
 
   out:
@@ -2304,7 +2322,13 @@ static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx,
                goto error;
        }
 
-       global.maxsock++;
+       /* Only increment maxsock for servers from the configuration. Dynamic
+        * servers at the moment are not taken into account for the estimation
+        * of the resources limits.
+        */
+       if (global.mode & MODE_STARTING)
+               global.maxsock++;
+
        srv->check.port = atol(args[*cur_arg+1]);
        /* if agentport was never set, we can use port */
        if (!(srv->flags & SRV_F_AGENTPORT))