From: Willy Tarreau Date: Wed, 7 Oct 2020 16:36:54 +0000 (+0200) Subject: MEDIUM: init: stop disabled proxies after initializing fdtab X-Git-Tag: v2.3-dev6~62 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02b092f00606c9de3a8f315831d274f93ffa4f08;p=thirdparty%2Fhaproxy.git MEDIUM: init: stop disabled proxies after initializing fdtab During the startup process we don't have any fdtab nor fd_updt for quite a long time, and as such some operations on the listeners are not permitted, such as fd_want_*/fd_stop_* or fd_delete(). The latter is of particular concern because it's used when stopping a disabled frontend, and it's performed very early during check_config_validity() while there is no fdtab yet. The trick till now relies on the listener's state which is a bit brittle. There is absolutely no valid reason for stopping a proxy's listeners this early, we can postpone it after init_pollers() which will at least have allocated fdtab. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index cb48fef2b0..a711ed842f 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -2235,10 +2235,13 @@ int check_config_validity() if (curproxy->state == PR_STSTOPPED) { - /* ensure we don't keep listeners uselessly bound */ - stop_proxy(curproxy); + /* ensure we don't keep listeners uselessly bound. We + * can't disable their listeners yet (fdtab not + * allocated yet) but let's skip them. + */ if (curproxy->table) { free((void *)curproxy->table->peers.name); + curproxy->table->peers.name = NULL; curproxy->table->peers.p = NULL; } continue; diff --git a/src/haproxy.c b/src/haproxy.c index eb4e9699a3..335ccb78ab 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2338,6 +2338,12 @@ static void init(int argc, char **argv) if (!global.node) global.node = strdup(hostname); + /* stop disabled proxies */ + for (px = proxies_list; px; px = px->next) { + if (px->state == PR_STSTOPPED) + stop_proxy(px); + } + if (!hlua_post_init()) exit(1);