From 220e0e0f7383a79fda0ba61bd1bf2076f5f74d72 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 26 Apr 2017 21:22:03 -0700 Subject: [PATCH] os: use kernel limit on pipe size if possible Fixes #20134 Change-Id: I92699d118c713179961c037a6bbbcbec4efa63ba Reviewed-on: https://go-review.googlesource.com/41823 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/os/pipe_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/os/pipe_test.go b/src/os/pipe_test.go index eb26b68f85..3b1c099319 100644 --- a/src/os/pipe_test.go +++ b/src/os/pipe_test.go @@ -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 { -- 2.50.0