BUG/MINOR: init: only keep rlim_fd_cur if max is unlimited
authorWilly Tarreau <w@1wt.eu>
Tue, 13 Oct 2020 13:36:08 +0000 (15:36 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 19 Oct 2020 06:41:09 +0000 (08:41 +0200)
On some operating systems, RLIM_INFINITY is set to -1 so that when the
hard limit on the number of FDs is set to unlimited, taking the MAX
of both values keeps rlim_fd_cur and everything works. But on other
systems this values is defined as the highest positive integer. This
is what was observed on a 32-bit AIX 5.1. The effect is that maxsock
becomes 2^31-1 and that fdtab allocation fails.

Note that a simple workaround consists in manually setting maxconn in
the global section.

Let's ignore unlimited as soon as we retrieve rlim_fd_max so that all
systems behave consistently.

This may be backported as far as 2.0, though it doesn't seem like it
has annoyed anyone.

(cherry picked from commit 2bd0f8147b0682ec962f59a5c38f03314f43a4f5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit bd2d932842afa5af41672f7e66483714537fcb3a)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/haproxy.c

index e490dc4..7985734 100644 (file)
@@ -3062,6 +3062,9 @@ int main(int argc, char **argv)
 
        /* take a copy of initial limits before we possibly change them */
        getrlimit(RLIMIT_NOFILE, &limit);
+
+       if (limit.rlim_max == RLIM_INFINITY)
+               limit.rlim_max = limit.rlim_cur;
        rlim_fd_cur_at_boot = limit.rlim_cur;
        rlim_fd_max_at_boot = limit.rlim_max;