diff --git a/lib/osutil/rlimit_unix.go b/lib/osutil/rlimit_unix.go index b0b6d5d8c..91405d00c 100644 --- a/lib/osutil/rlimit_unix.go +++ b/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