Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/utils/fdlimit_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,13 @@ func getFdLimit() (int, error) {
}
return int(limit.Cur), nil
}

// getFdMaxLimit retrieves the maximum number of file descriptors this process is
// allowed to request for itself.
func getFdMaxLimit() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Max), nil
}
12 changes: 11 additions & 1 deletion cmd/utils/fdlimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@

package utils

import "testing"
import (
"fmt"
"testing"
)

// TestFileDescriptorLimits simply tests whether the file descriptor allowance
// per this process can be retrieved.
func TestFileDescriptorLimits(t *testing.T) {
target := 4096
hardlimit, err := getFdMaxLimit()
if err != nil {
t.Fatal(err)
}
if hardlimit < target {
t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
}

if limit, err := getFdLimit(); err != nil || limit <= 0 {
t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
Expand Down
10 changes: 10 additions & 0 deletions cmd/utils/fdlimit_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ func getFdLimit() (int, error) {
}
return int(limit.Cur), nil
}

// getFdMaxLimit retrieves the maximum number of file descriptors this process is
// allowed to request for itself.
func getFdMaxLimit() (int, error) {
var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err
}
return int(limit.Max), nil
}
6 changes: 6 additions & 0 deletions cmd/utils/fdlimit_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ func getFdLimit() (int, error) {
// Please see raiseFdLimit for the reason why we use hard coded 16K as the limit
return 16384, nil
}

// getFdMaxLimit retrieves the maximum number of file descriptors this process is
// allowed to request for itself.
func getFdMaxLimit() (int, error) {
return getFdLimit()
}