Skip to content

Commit

Permalink
Fix "failed setting rlimit: invalid argument" on osx
Browse files Browse the repository at this point in the history
Running on osx, the attempt to change the rlimit fails with "invalid argument".

It appears that the value of rlimit.Max is `9223372036854775807`, and that
trying to set to that value fails. More on this at
golang/go#30401.

We fix this by setting the value to the somewhat magic 24576 when on osx (darwin).
  • Loading branch information
madjar committed Aug 24, 2020
1 parent 3341144 commit f7ed289
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"syscall"
)
Expand Down Expand Up @@ -80,6 +81,9 @@ func raiseFdLimit() (uint64, error) {
if rlimit.Cur < rlimit.Max {
oldVal := rlimit.Cur
rlimit.Cur = rlimit.Max
if runtime.GOOS == "darwin" && rlimit.Cur > 24576 {
rlimit.Cur = 24576
}
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
if err != nil {
fmt.Fprintf(os.Stderr, "failed setting rlimit: %s", err)
Expand Down

0 comments on commit f7ed289

Please sign in to comment.