diff --git a/pkg/sys/rlimit-file_nix.go b/pkg/sys/rlimit-file_nix.go index 8afdc31ea..ac01be5f0 100644 --- a/pkg/sys/rlimit-file_nix.go +++ b/pkg/sys/rlimit-file_nix.go @@ -18,7 +18,10 @@ package sys -import "syscall" +import ( + "runtime" + "syscall" +) // GetMaxOpenFileLimit - returns maximum file descriptor number that can be opened by this process. func GetMaxOpenFileLimit() (curLimit, maxLimit uint64, err error) { @@ -33,6 +36,13 @@ func GetMaxOpenFileLimit() (curLimit, maxLimit uint64, err error) { // SetMaxOpenFileLimit - sets maximum file descriptor number that can be opened by this process. func SetMaxOpenFileLimit(curLimit, maxLimit uint64) error { + if runtime.GOOS == "darwin" && curLimit > 10240 { + // The max file limit is 10240, even though + // the max returned by Getrlimit is 1<<63-1. + // This is OPEN_MAX in sys/syslimits.h. + // refer https://github.com/golang/go/issues/30401 + curLimit = 10240 + } rlimit := syscall.Rlimit{Cur: curLimit, Max: maxLimit} return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit) }