From cc87648527cfbc7dd8fdb7484176ac62345dfed5 Mon Sep 17 00:00:00 2001 From: Jeremy Schlatter Date: Wed, 18 Sep 2019 20:04:56 -0700 Subject: [PATCH] Work around getrlimit syscall error on darwin (#286) Fixes #285 --- ibazel/main_unix.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ibazel/main_unix.go b/ibazel/main_unix.go index 7fc04594..e2767536 100644 --- a/ibazel/main_unix.go +++ b/ibazel/main_unix.go @@ -16,7 +16,10 @@ package main -import "syscall" +import ( + "runtime" + "syscall" +) func setUlimit() error { var lim syscall.Rlimit @@ -31,6 +34,15 @@ func setUlimit() error { // http://man7.org/linux/man-pages/man2/getrlimit.2.html lim.Cur = lim.Max + // If we're on darwin, work around the fact that Getrlimit reports + // the wrong value. See https://github.com/golang/go/issues/30401 + if runtime.GOOS == "darwin" && lim.Cur > 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. + lim.Cur = 10240 + } + err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim) if err != nil { return err