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.
diff --git a/include/haproxy/defaults.h b/include/haproxy/defaults.h
index f5f3b54..0dc2581 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 19463f2..3def1ed 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2380,7 +2380,7 @@
/* 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;