]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: cap RLIMIT_NOFILE soft limit in TestRlimit on darwin
authorCholerae Hu <choleraehyq@gmail.com>
Wed, 5 Aug 2020 05:52:32 +0000 (13:52 +0800)
committerTobias Klauser <tobias.klauser@gmail.com>
Mon, 17 Aug 2020 09:14:51 +0000 (09:14 +0000)
On some machines, kern.maxfilesperproc is 4096. If Rlimit.Cur is larger
than that, Setrlimit will get an errEINVAL.

Fixes #40564.

Change-Id: Ib94303c790a489ff0559c88d41a021e514d18f8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/246658
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/syscall/syscall_unix_test.go

index 13b79ca8d81b152eb5ce3106d3c2b169b6a8e4f6..3c7982eefec80c47da144c28f5b5ec9c6ade452a 100644 (file)
@@ -336,11 +336,11 @@ func TestRlimit(t *testing.T) {
        }
        set := rlimit
        set.Cur = set.Max - 1
-       if runtime.GOOS == "darwin" && set.Cur > 10240 {
-               // The max file limit is 10240, even though
-               // the max returned by Getrlimit is 1<<63-1.
-               // This is OPEN_MAX in sys/syslimits.h.
-               set.Cur = 10240
+       if runtime.GOOS == "darwin" && set.Cur > 4096 {
+               // rlim_min for RLIMIT_NOFILE should be equal to
+               // or lower than kern.maxfilesperproc, which on
+               // some machines are 4096. See #40564.
+               set.Cur = 4096
        }
        err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &set)
        if err != nil {
@@ -353,8 +353,8 @@ func TestRlimit(t *testing.T) {
        }
        set = rlimit
        set.Cur = set.Max - 1
-       if runtime.GOOS == "darwin" && set.Cur > 10240 {
-               set.Cur = 10240
+       if runtime.GOOS == "darwin" && set.Cur > 4096 {
+               set.Cur = 4096
        }
        if set != get {
                t.Fatalf("Rlimit: change failed: wanted %#v got %#v", set, get)