]> Cypherpunks repositories - gostls13.git/commitdiff
os: use kernel limit on pipe size if possible
authorIan Lance Taylor <iant@golang.org>
Thu, 27 Apr 2017 04:22:03 +0000 (21:22 -0700)
committerIan Lance Taylor <iant@golang.org>
Thu, 27 Apr 2017 04:42:21 +0000 (04:42 +0000)
Fixes #20134

Change-Id: I92699d118c713179961c037a6bbbcbec4efa63ba
Reviewed-on: https://go-review.googlesource.com/41823
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/pipe_test.go

index eb26b68f85e32c9f42defa4d43fd0fa529ebad7e..3b1c099319f0596b9930369459eb4a1dbc40ed97 100644 (file)
@@ -10,10 +10,13 @@ package os_test
 import (
        "fmt"
        "internal/testenv"
+       "io/ioutil"
        "os"
        osexec "os/exec"
        "os/signal"
        "runtime"
+       "strconv"
+       "strings"
        "syscall"
        "testing"
        "time"
@@ -120,6 +123,19 @@ func testClosedPipeRace(t *testing.T, read bool) {
                t.Skip("FreeBSD does not use the poller; issue 19093")
        }
 
+       limit := 1
+       if !read {
+               // Get the amount we have to write to overload a pipe
+               // with no reader.
+               limit = 65537
+               if b, err := ioutil.ReadFile("/proc/sys/fs/pipe-max-size"); err == nil {
+                       if i, err := strconv.Atoi(strings.TrimSpace(string(b))); err == nil {
+                               limit = i + 1
+                       }
+               }
+               t.Logf("using pipe write limit of %d", limit)
+       }
+
        r, w, err := os.Pipe()
        if err != nil {
                t.Fatal(err)
@@ -146,8 +162,7 @@ func testClosedPipeRace(t *testing.T, read bool) {
                }
        }()
 
-       // A slice larger than PIPE_BUF.
-       var b [65537]byte
+       b := make([]byte, limit)
        if read {
                _, err = r.Read(b[:])
        } else {