From 8b16b725411d72d3bab184bcd0c0253dddeedeb1 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 4 Dec 2024 15:58:49 +0100 Subject: [PATCH] BUG/MINOR: init: do not call fork_poller() for non-forked processes In 3.1-dev10, commit 8dd4efe42f ("MAJOR: mworker: move master-worker fork in init()") made the fork_poller() code unconditional, while it is only desirable for processes that have been forked from a parent (standalone daemon mode) or from a master (master-worker mode). The call can be expensive in some cases as it will create a new poller, scan and try to migrate to it all existing FDs till the highest known one. With very high numbers of FDs, this can take several seconds to start. This should be backported to 3.1. --- src/haproxy.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/haproxy.c b/src/haproxy.c index c3538748c..eac6329a1 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -3603,7 +3603,14 @@ int main(int argc, char **argv) devnullfd = -1; } pid = getpid(); /* update pid */ - fork_poller(); + + /* This call is expensive, as it creates a new poller, scans and tries + * to migrate to it all existing FDs until the highest known one. With + * very high numbers of FDs, this can take several seconds to start. + * So, it's only desirable for modes, when we perform a fork(). + */ + if (global.mode & MODE_DAEMON) + fork_poller(); /* pass through every cli socket, and check if it's bound to * the current process and if it exposes listeners sockets.