diff options
| author | Russ Cox <rsc@golang.org> | 2015-07-22 16:50:00 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-07-22 21:37:18 +0000 |
| commit | 92390e47d81713d13b0d9890bf8b153f142a5b8a (patch) | |
| tree | 5d61d265f127cab0db0a35049ef3f815767cfd33 /src/os/exec/exec_test.go | |
| parent | a5caa7c94eda915ee5e5ff82d81a22b8392d84aa (diff) | |
| download | go-92390e47d81713d13b0d9890bf8b153f142a5b8a.tar.xz | |
os/exec: close read pipe if copy to io.Writer fails
Fixes #10400.
Change-Id: Ic486cb8af4c40660fd1a2e3d10986975acba3f19
Reviewed-on: https://go-review.googlesource.com/12537
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/os/exec/exec_test.go')
| -rw-r--r-- | src/os/exec/exec_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 6888d29cd8..28be21ce63 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -786,3 +786,33 @@ func TestIgnorePipeErrorOnSuccess(t *testing.T) { t.Errorf("output = %q; want %q", got, want) } } + +type badWriter struct{} + +func (w *badWriter) Write(data []byte) (int, error) { + return 0, io.ErrUnexpectedEOF +} + +func TestClosePipeOnCopyError(t *testing.T) { + testenv.MustHaveExec(t) + + if runtime.GOOS == "windows" || runtime.GOOS == "plan9" { + t.Skipf("skipping test on %s - no yes command", runtime.GOOS) + } + cmd := exec.Command("yes") + cmd.Stdout = new(badWriter) + c := make(chan int, 1) + go func() { + err := cmd.Run() + if err == nil { + t.Errorf("yes completed successfully") + } + c <- 1 + }() + select { + case <-c: + // ok + case <-time.After(5 * time.Second): + t.Fatalf("yes got stuck writing to bad writer") + } +} |
