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

This commit is contained in:
Paul Brit 2019-12-02 23:26:22 -07:00 committed by Jakob Borg
parent b3fd9a8d53
commit eca156fd7f
1 changed files with 14 additions and 1 deletions

View File

@ -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