Explorar o código

lib/osutil: Increase maxfiles on macOS properly (fixes #6206) (#6207)

Paul Brit %!s(int64=5) %!d(string=hai) anos
pai
achega
eca156fd7f
Modificáronse 1 ficheiros con 14 adicións e 1 borrados
  1. 14 1
      lib/osutil/rlimit_unix.go

+ 14 - 1
lib/osutil/rlimit_unix.go

@@ -8,7 +8,14 @@
 
 package osutil
 
-import "syscall"
+import (
+	"runtime"
+	"syscall"
+)
+
+const (
+	darwinOpenMax = 10240
+)
 
 // MaximizeOpenFileLimit tries to set the resource limit RLIMIT_NOFILE (number
 // of open file descriptors) to the max (hard limit), if the current (soft
@@ -26,6 +33,12 @@ func MaximizeOpenFileLimit() (int, error) {
 		return int(lim.Cur), nil
 	}
 
+	// macOS doesn't like a soft limit greater then OPEN_MAX
+	// See also: man setrlimit
+	if runtime.GOOS == "darwin" && lim.Max > darwinOpenMax {
+		lim.Cur = darwinOpenMax
+	}
+
 	// Try to increase the limit to the max.
 	oldLimit := lim.Cur
 	lim.Cur = lim.Max