From 3380ee2520165187c3d1476c46d16bc76376d4d4 Mon Sep 17 00:00:00 2001 From: Bryan Mills Date: Tue, 4 Oct 2022 19:55:56 +0000 Subject: [PATCH] Revert "os/exec: make StdoutPipe and StderrPipe safe to Close concurrently" This reverts CL 437176. Reason for revert: broke programs that plumb StdoutPipe from one command to Stdin on another and then call Wait on the former. os/exec itself uses a type-assertion to *os.File to determine whether to copy stdin using a goroutine or just pass a file descriptor. An early Wait using a *os.File is benign (because closing the pipe doesn't close the child's inherited file descriptor), but an early Wait using a non-*os.File is not. Updates #50436. Change-Id: I4a2993e290982834f91696d890dfe77364c0cc50 Reviewed-on: https://go-review.googlesource.com/c/go/+/438695 Auto-Submit: Bryan Mills TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor --- src/os/exec/exec.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index 66441ecadd..8e6f709a2f 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -808,9 +808,8 @@ func (c *Cmd) StdoutPipe() (io.ReadCloser, error) { } c.Stdout = pw c.childIOFiles = append(c.childIOFiles, pw) - rc := &closeOnce{File: pr} - c.parentIOPipes = append(c.parentIOPipes, rc) - return rc, nil + c.parentIOPipes = append(c.parentIOPipes, pr) + return pr, nil } // StderrPipe returns a pipe that will be connected to the command's @@ -834,9 +833,8 @@ func (c *Cmd) StderrPipe() (io.ReadCloser, error) { } c.Stderr = pw c.childIOFiles = append(c.childIOFiles, pw) - rc := &closeOnce{File: pr} - c.parentIOPipes = append(c.parentIOPipes, rc) - return rc, nil + c.parentIOPipes = append(c.parentIOPipes, pr) + return pr, nil } // prefixSuffixSaver is an io.Writer which retains the first N bytes -- 2.50.0