Commit 220e0e0f authored by Ian Lance Taylor's avatar Ian Lance Taylor

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 <iant@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 35cbc3b5
...@@ -10,10 +10,13 @@ package os_test ...@@ -10,10 +10,13 @@ package os_test
import ( import (
"fmt" "fmt"
"internal/testenv" "internal/testenv"
"io/ioutil"
"os" "os"
osexec "os/exec" osexec "os/exec"
"os/signal" "os/signal"
"runtime" "runtime"
"strconv"
"strings"
"syscall" "syscall"
"testing" "testing"
"time" "time"
...@@ -120,6 +123,19 @@ func testClosedPipeRace(t *testing.T, read bool) { ...@@ -120,6 +123,19 @@ func testClosedPipeRace(t *testing.T, read bool) {
t.Skip("FreeBSD does not use the poller; issue 19093") 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() r, w, err := os.Pipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -146,8 +162,7 @@ func testClosedPipeRace(t *testing.T, read bool) { ...@@ -146,8 +162,7 @@ func testClosedPipeRace(t *testing.T, read bool) {
} }
}() }()
// A slice larger than PIPE_BUF. b := make([]byte, limit)
var b [65537]byte
if read { if read {
_, err = r.Read(b[:]) _, err = r.Read(b[:])
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment