Skip to content

Commit

Permalink
cmd/osutil: Increase maxfiles on macOS properly (Fixes syncthing#6206)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrit committed Dec 3, 2019
1 parent b3fd9a8 commit 3378da9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ require (
github.com/maruel/panicparse v1.3.0
github.com/mattn/go-isatty v0.0.10
github.com/minio/sha256-simd v0.1.1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/onsi/ginkgo v1.9.0 // indirect
github.com/onsi/gomega v1.6.0 // indirect
github.com/oschwald/geoip2-golang v1.3.0
Expand Down
15 changes: 14 additions & 1 deletion lib/osutil/rlimit_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@

package osutil

import "syscall"
import (
"runtime"
"syscall"
)

const (
darwinOpenMax = 10240
)

// MaximizeOpenFileLimit tries to set the resource limit RLIMIT_NOFILE (number
// of open file descriptors) to the max (hard limit), if the current (soft
Expand All @@ -26,6 +33,12 @@ func MaximizeOpenFileLimit() (int, error) {
return int(lim.Cur), nil
}

// macOS doesn't like a soft limit greater then OPEN_MAX
// See also: man setrlimit
if runtime.GOOS == "darwin" && lim.Max > darwinOpenMax {
lim.Cur = darwinOpenMax
}

// Try to increase the limit to the max.
oldLimit := lim.Cur
lim.Cur = lim.Max
Expand Down

0 comments on commit 3378da9

Please sign in to comment.