on darwin fallback to maximum possible rlimit (#9859)

fixes #9857
master
Harshavardhana 4 years ago committed by GitHub
parent f5e1b3d09e
commit 7c061fa3b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      pkg/sys/rlimit-file_nix.go

@ -18,7 +18,10 @@
package sys package sys
import "syscall" import (
"runtime"
"syscall"
)
// GetMaxOpenFileLimit - returns maximum file descriptor number that can be opened by this process. // GetMaxOpenFileLimit - returns maximum file descriptor number that can be opened by this process.
func GetMaxOpenFileLimit() (curLimit, maxLimit uint64, err error) { 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. // SetMaxOpenFileLimit - sets maximum file descriptor number that can be opened by this process.
func SetMaxOpenFileLimit(curLimit, maxLimit uint64) error { 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} rlimit := syscall.Rlimit{Cur: curLimit, Max: maxLimit}
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit) return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
} }

Loading…
Cancel
Save