From 8dca19549ab3b30342b92b56b2c766a6a4ec8d0e Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 1 Mar 2019 10:21:55 +0100 Subject: [PATCH] BUG/MINOR: mworker: be careful to restore the original rlim_fd_cur/max on reload When the master re-execs itself on reload, it doesn't restore the initial rlim_fd_cur/rlim_fd_max values, which have been modified by the ulimit-n or global maxconn directives. This is a problem, because if these values were set really low it could prevent the process from restarting, and if they were set very high, this could have some implications on the restart time, or later on the computed maxconn. Let's simply reset these values to the ones we had at boot to maintain the system in a consistent state. A backport could be performed to 1.9 and maybe 1.8. This patch depends on the two previous ones. --- src/haproxy.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/haproxy.c b/src/haproxy.c index 0d42bc0b7..40865f0a3 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -716,6 +716,7 @@ void mworker_reload() int next_argc = 0; int j; char *msg = NULL; + struct rlimit limit; struct per_thread_deinit_fct *ptdf; mworker_block_signals(); @@ -739,6 +740,16 @@ void mworker_reload() if (fdtab) deinit_pollers(); + /* restore the initial FD limits */ + limit.rlim_cur = rlim_fd_cur_at_boot; + limit.rlim_max = rlim_fd_max_at_boot; + if (setrlimit(RLIMIT_NOFILE, &limit) == -1) { + getrlimit(RLIMIT_NOFILE, &limit); + ha_warning("Failed to restore initial FD limits (cur=%u max=%u), using cur=%u max=%u\n", + rlim_fd_cur_at_boot, rlim_fd_max_at_boot, + (unsigned int)limit.rlim_cur, (unsigned int)limit.rlim_max); + } + /* compute length */ while (next_argv[next_argc]) next_argc++;