From 2078d4b1f77f70ac110022c2b5ac4644e4c01640 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Thu, 9 Mar 2023 14:28:44 +0100 Subject: [PATCH] BUG/MINOR: mworker: use MASTER_MAXCONN as default maxconn value In environments where SYSTEM_MAXCONN is defined when compiling, the master will use this value instead of the original minimal value which was set to 100. When this happens, the master process could allocate RAM excessively since it does not need to have an high maxconn. (For example if SYSTEM_MAXCONN was set to 100000 or more) This patch fixes the issue by using the new define MASTER_MAXCONN which define a default maxconn of 100 for the master process. Must be backported as far as 2.5. --- include/haproxy/defaults.h | 10 ++++++++++ src/haproxy.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h index f5f3b5459..0dc25818d 100644 --- a/include/haproxy/defaults.h +++ b/include/haproxy/defaults.h @@ -289,6 +289,16 @@ #define DEFAULT_MAXCONN 100 #endif +/* Define a maxconn which will be used in the master process once it re-exec to + * the MODE_MWORKER_WAIT and won't change when SYSTEM_MAXCONN is set. + * + * 100 must be enough for the master since it only does communication between + * the master and the workers, and the master CLI. + */ +#ifndef MASTER_MAXCONN +#define MASTER_MAXCONN 100 +#endif + /* Minimum check interval for spread health checks. Servers with intervals * greater than or equal to this value will have their checks spread apart * and will be considered when searching the minimal interval. diff --git a/src/haproxy.c b/src/haproxy.c index 19463f29e..3def1ed98 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2380,7 +2380,7 @@ static void init(int argc, char **argv) /* set the default maxconn in the master, but let it be rewritable with -n */ if (global.mode & MODE_MWORKER_WAIT) - global.maxconn = DEFAULT_MAXCONN; + global.maxconn = MASTER_MAXCONN; if (cfg_maxconn > 0) global.maxconn = cfg_maxconn;