Skip to content

Commit

Permalink
dolt/go/cmd/dolt/fileno_check_darwin.go: Fix setrlimit(RLIMIT_NOFILE,…
Browse files Browse the repository at this point in the history
… ...) on Darwin.

It turns out rlim_max from getrlimit(RLIMIT_NOFILE, ...) is not a valid value
for rlim_cur in setrlimit(RLIMIT_NOFILE, ...) on Darwin. Golang used to silently
fix this for us, but it stopped doing it. See
golang/go#30401.

Take reasonable steps to work around it for now.
  • Loading branch information
Aaron Son committed Jul 18, 2019
1 parent 7a87590 commit 5d4fa15
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion go/cmd/dolt/fileno_check_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ var yellow = color.New(color.FgYellow).SprintFunc()

const warningThreshold = 4096

// Darwin setrlimit fails with EINVAL if
// lim.Cur > OPEN_MAX (from sys/syslimits.h), regardless of lim.Max.
// Just choose a reasonable number here.
const darwinMaxFiles = 8192

func warnIfMaxFilesTooLow() {
var lim unix.Rlimit
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &lim); err != nil {
return
}
lim.Cur = lim.Max
if lim.Cur > darwinMaxFiles {
lim.Cur = darwinMaxFiles
}
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &lim); err != nil {
return
}
Expand All @@ -30,6 +38,5 @@ func warnIfMaxFilesTooLow() {
cli.Printf("%s\n", yellow(fmt.Sprintf("Only %d file descriptors are available for this process, which is less than the recommended amount, %d.", lim.Cur, warningThreshold)))
cli.Printf("%s\n", yellow("You may experience I/O errors by continuing to run dolt in this configuration."))
cli.Printf("\n")

}
}

0 comments on commit 5d4fa15

Please sign in to comment.