]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "os/exec: make StdoutPipe and StderrPipe safe to Close concurrently"
authorBryan Mills <bcmills@google.com>
Tue, 4 Oct 2022 19:55:56 +0000 (19:55 +0000)
committerGopher Robot <gobot@golang.org>
Tue, 4 Oct 2022 21:17:23 +0000 (21:17 +0000)
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 <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/exec/exec.go

index 66441ecaddd2f918f70233f06cb96ea5f26bcb64..8e6f709a2f13b5fe086039f686fba7353c6495fa 100644 (file)
@@ -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