浏览代码

Always allow extra file descriptors when setting the connection maximum

When setting the maximum number of connections allowed by the OS,
always allow some extra file descriptors for other files.

Fixes bug 22797; bugfix on 0.2.0.10-alpha.
teor 7 年之前
父节点
当前提交
878e0d45a5
共有 2 个文件被更改,包括 16 次插入7 次删除
  1. 4 0
      changes/bug22797
  2. 12 7
      src/common/compat.c

+ 4 - 0
changes/bug22797

@@ -0,0 +1,4 @@
+  o Minor bugfixes (file limits):
+    - When setting the maximum number of connections allowed by the OS,
+      always allow some extra file descriptors for other files.
+      Fixes bug 22797; bugfix on 0.2.0.10-alpha.

+ 12 - 7
src/common/compat.c

@@ -1568,19 +1568,24 @@ set_max_file_descriptors(rlim_t limit, int *max_out)
   if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
   if (setrlimit(RLIMIT_NOFILE, &rlim) != 0) {
     int bad = 1;
     int bad = 1;
 #ifdef OPEN_MAX
 #ifdef OPEN_MAX
-    if (errno == EINVAL && OPEN_MAX < rlim.rlim_cur) {
+    uint64_t try_limit = OPEN_MAX - ULIMIT_BUFFER;
+    if (errno == EINVAL && try_limit < rlim.rlim_cur) {
       /* On some platforms, OPEN_MAX is the real limit, and getrlimit() is
       /* On some platforms, OPEN_MAX is the real limit, and getrlimit() is
        * full of nasty lies.  I'm looking at you, OSX 10.5.... */
        * full of nasty lies.  I'm looking at you, OSX 10.5.... */
-      rlim.rlim_cur = OPEN_MAX;
+      rlim.rlim_cur = try_limit;
       if (setrlimit(RLIMIT_NOFILE, &rlim) == 0) {
       if (setrlimit(RLIMIT_NOFILE, &rlim) == 0) {
         if (rlim.rlim_cur < (rlim_t)limit) {
         if (rlim.rlim_cur < (rlim_t)limit) {
           log_warn(LD_CONFIG, "We are limited to %lu file descriptors by "
           log_warn(LD_CONFIG, "We are limited to %lu file descriptors by "
-                 "OPEN_MAX, and ConnLimit is %lu.  Changing ConnLimit; sorry.",
+                   "OPEN_MAX (%lu), and ConnLimit is %lu.  Changing "
-                   (unsigned long)OPEN_MAX, (unsigned long)limit);
+                   "ConnLimit; sorry.",
+                   (unsigned long)try_limit, (unsigned long)OPEN_MAX,
+                   (unsigned long)limit);
         } else {
         } else {
-          log_info(LD_CONFIG, "Dropped connection limit to OPEN_MAX (%lu); "
+          log_info(LD_CONFIG, "Dropped connection limit to %lu based on "
-                   "Apparently, %lu was too high and rlimit lied to us.",
+                   "OPEN_MAX (%lu); Apparently, %lu was too high and rlimit "
-                   (unsigned long)OPEN_MAX, (unsigned long)rlim.rlim_max);
+                   "lied to us.",
+                   (unsigned long)try_limit, (unsigned long)OPEN_MAX,
+                   (unsigned long)rlim.rlim_max);
         }
         }
         bad = 0;
         bad = 0;
       }
       }