mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 21:31:28 +02:00
BUG/MINOR: checks: make external-checks restore the original rlim_fd_cur/max
It's not normal that external processes are run with high FD limits, as quite often such processes (especially shell scripts) will iterate over all FDs to close them. Ideally we should even provide a tunable with the external-check directive to adjust this value, but at least we need to restore it to the value that was active when starting haproxy (before it was adjusted for maxconn). Additionally with very low maxconn values causing rlim_fd_cur to be low, some heavy checks could possibly fail. This was also mentioned in issue #45. Currently the following config and scripts report this : $ cat rlim.cfg global maxconn 500000 external-check listen www bind :8001 timeout client 5s timeout server 5s timeout connect 5s option external-check external-check command "$PWD/sleep1.sh" server local 127.0.0.1:80 check inter 1s $ cat sleep1.sh #!/bin/sh /bin/sleep 0.1 echo -n "soft: ";ulimit -S -n echo -n "hard: ";ulimit -H -n # ./haproxy -db -f rlim.cfg soft: 1000012 hard: 1000012 soft: 1000012 hard: 1000012 Now with the fix : # ./haproxy -db -f rlim.cfg soft: 1024 hard: 4096 soft: 1024 hard: 4096 This fix should be backported to stable versions but it depends on "MINOR: global: keep a copy of the initial rlim_fd_cur and rlim_fd_max values" and "BUG/MINOR: init: never lower rlim_fd_max".
This commit is contained in:
parent
e5cfdacb83
commit
9f6dc72477
12
src/checks.c
12
src/checks.c
@ -22,6 +22,7 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user