From eca156fd7f8d2083d6750b20cd4444126a2162fa Mon Sep 17 00:00:00 2001 From: Paul Brit Date: Mon, 2 Dec 2019 23:26:22 -0700 Subject: [PATCH] lib/osutil: Increase maxfiles on macOS properly (fixes #6206) (#6207) --- lib/osutil/rlimit_unix.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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