The following code terminates with a deadlock error when run in isolation. If we replace the usage of io.Pipe with cmd.StdinPipe(), the program terminates normally with the expected error from cmd.Wait().
This is on Darwin 14.1.0 with go 1.4.2.
package main
import (
"fmt"
"io"
"syscall"
)
import "os/exec"
func main() {
pr, pw := io.Pipe()
cmd := exec.Command("/bin/bash", "-c", "cat")
cmd.Stdin = pr
started := make(chan error)
done := make(chan error)
go func() {
started <- cmd.Start()
done <- cmd.Wait()
}()
<-started
println("Started")
pw.Write([]byte("hello"))
cmd.Process.Signal(syscall.SIGTERM)
err := <-done
println("Done")
if err != nil {
fmt.Printf("wait err: %s\n", err.Error())
}
}