|
@@ -22,11 +22,12 @@ import "syscall"
|
|
|
|
|
|
|
|
// Raise tries to maximize the file descriptor allowance of this process
|
|
// Raise tries to maximize the file descriptor allowance of this process
|
|
|
// to the maximum hard-limit allowed by the OS.
|
|
// to the maximum hard-limit allowed by the OS.
|
|
|
-func Raise(max uint64) error {
|
|
|
|
|
|
|
+// Returns the size it was set to (may differ from the desired 'max')
|
|
|
|
|
+func Raise(max uint64) (uint64, error) {
|
|
|
// Get the current limit
|
|
// Get the current limit
|
|
|
var limit syscall.Rlimit
|
|
var limit syscall.Rlimit
|
|
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
|
|
- return err
|
|
|
|
|
|
|
+ return 0, err
|
|
|
}
|
|
}
|
|
|
// Try to update the limit to the max allowance
|
|
// Try to update the limit to the max allowance
|
|
|
limit.Cur = limit.Max
|
|
limit.Cur = limit.Max
|
|
@@ -34,9 +35,13 @@ func Raise(max uint64) error {
|
|
|
limit.Cur = max
|
|
limit.Cur = max
|
|
|
}
|
|
}
|
|
|
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
|
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
|
|
- return err
|
|
|
|
|
|
|
+ return 0, err
|
|
|
|
|
+ }
|
|
|
|
|
+ // MacOS can silently apply further caps, so retrieve the actually set limit
|
|
|
|
|
+ if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
|
|
|
|
|
+ return 0, err
|
|
|
}
|
|
}
|
|
|
- return nil
|
|
|
|
|
|
|
+ return limit.Cur, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Current retrieves the number of file descriptors allowed to be opened by this
|
|
// Current retrieves the number of file descriptors allowed to be opened by this
|