From: Amaury Denoyelle Date: Thu, 29 Jul 2021 13:39:43 +0000 (+0200) Subject: MINOR: check: do not increment global maxsock at runtime X-Git-Tag: v2.5-dev4~59 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=403dce8e5a912bb3d2d78b62e3252b294d894de5;p=thirdparty%2Fhaproxy.git MINOR: check: do not increment global maxsock at runtime 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. --- diff --git a/src/check.c b/src/check.c index 1391d113c3..c2ab8e830a 100644 --- a/src/check.c +++ b/src/check.c @@ -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))