Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix setting ulimit #6319

Merged
merged 2 commits into from
May 14, 2019
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
2 changes: 1 addition & 1 deletion cmd/ipfs/util/ulimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ManageFdLimit() (changed bool, newLimit uint64, err error) {
return false, 0, err
}

if maxFds <= soft {
if targetLimit <= soft {
return false, 0, nil
}

Expand Down
18 changes: 6 additions & 12 deletions cmd/ipfs/util/ulimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestManageFdLimit(t *testing.T) {
t.Errorf("Cannot manage file descriptors")
}

if maxFds != uint64(2048) {
if maxFds != uint64(8192) {
t.Errorf("Maximum file descriptors default value changed")
}
}
Expand All @@ -38,16 +38,15 @@ func TestManageInvalidNFds(t *testing.T) {
t.Fatal("Cannot set the IPFS_FD_MAX env variable")
}

// call to check and set the maximum file descriptor from the env
setMaxFds()
t.Logf("setting ulimit to %d, max %d, cur %d", value, rlimit.Max, rlimit.Cur)

if _, _, err := ManageFdLimit(); err == nil {
t.Errorf("ManageFdLimit should return an error")
if changed, new, err := ManageFdLimit(); err == nil {
t.Errorf("ManageFdLimit should return an error: changed %t, new: %d", changed, new)
} else if err != nil {
flag := strings.Contains(err.Error(),
"cannot set rlimit, IPFS_FD_MAX is larger than the hard limit")
"failed to raise ulimit to IPFS_FD_MAX")
if !flag {
t.Errorf("ManageFdLimit returned unexpected error")
t.Error("ManageFdLimit returned unexpected error", err)
}
}

Expand All @@ -74,11 +73,6 @@ func TestManageFdLimitWithEnvSet(t *testing.T) {
t.Fatal("Cannot set the IPFS_FD_MAX env variable")
}

setMaxFds()
if maxFds != uint64(value) {
t.Errorf("The maxfds is not set from IPFS_FD_MAX")
}

if _, _, err = ManageFdLimit(); err != nil {
t.Errorf("Cannot manage file descriptor count")
}
Expand Down