diff --git a/src/checks.c b/src/checks.c index 6d7b6aa27..235917642 100644 --- a/src/checks.c +++ b/src/checks.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -1965,6 +1966,7 @@ static int connect_proc_chk(struct task *t) if (pid == 0) { /* Child */ extern char **environ; + struct rlimit limit; int fd; /* close all FDs. Keep stdin/stdout/stderr in verbose mode */ @@ -1972,6 +1974,16 @@ static int connect_proc_chk(struct task *t) my_closefrom(fd); + /* 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("External check: 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); + } + environ = check->envp; extchk_setenv(check, EXTCHK_HAPROXY_SERVER_CURCONN, ultoa_r(s->cur_sess, buf, sizeof(buf))); execvp(px->check_command, check->argv);