From c318e3472ebc3ca6f30a17fdf24b99992145b404 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 10 May 2019 23:20:04 -0700 Subject: [PATCH 1/2] fix ulimit tests Not sure why CI wasn't failing. License: MIT Signed-off-by: Steven Allen --- cmd/ipfs/util/ulimit_test.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/cmd/ipfs/util/ulimit_test.go b/cmd/ipfs/util/ulimit_test.go index 2a5923f63..160f290fe 100644 --- a/cmd/ipfs/util/ulimit_test.go +++ b/cmd/ipfs/util/ulimit_test.go @@ -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") } } @@ -38,16 +38,13 @@ 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() - if _, _, err := ManageFdLimit(); err == nil { t.Errorf("ManageFdLimit should return an error") } 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) } } @@ -74,11 +71,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") } From bff8326b9771b5b235111b98bde29887be954006 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 13 May 2019 14:07:53 -0700 Subject: [PATCH 2/2] ulimit: fix setting ulimit License: MIT Signed-off-by: Steven Allen --- cmd/ipfs/util/ulimit.go | 2 +- cmd/ipfs/util/ulimit_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/ipfs/util/ulimit.go b/cmd/ipfs/util/ulimit.go index 6500d6b7c..e36ed7510 100644 --- a/cmd/ipfs/util/ulimit.go +++ b/cmd/ipfs/util/ulimit.go @@ -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 } diff --git a/cmd/ipfs/util/ulimit_test.go b/cmd/ipfs/util/ulimit_test.go index 160f290fe..0b6a227a5 100644 --- a/cmd/ipfs/util/ulimit_test.go +++ b/cmd/ipfs/util/ulimit_test.go @@ -38,8 +38,10 @@ func TestManageInvalidNFds(t *testing.T) { t.Fatal("Cannot set the IPFS_FD_MAX env variable") } - if _, _, err := ManageFdLimit(); err == nil { - t.Errorf("ManageFdLimit should return an error") + t.Logf("setting ulimit to %d, max %d, cur %d", value, rlimit.Max, rlimit.Cur) + + 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(), "failed to raise ulimit to IPFS_FD_MAX")