From 7c061fa3b69202bf7cf02d9b69819d8da52c463d Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 17 Jun 2020 07:47:42 -0700 Subject: [PATCH] on darwin fallback to maximum possible rlimit (#9859) fixes #9857 --- pkg/sys/rlimit-file_nix.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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) }