I hope this isn't a red herring but in constructing a self-contained
example I triggered a deadlock. Perhaps the deadlock is the answer to my
question or perhaps it is another issue. Either way this code does not seem
malformed:
func main() {
cmdName := "/bin/bash"
cmdArgs := []string{
"-c",
"while true; do echo step; sleep 1; done",
}
cmdStdinR, cmdStdinW := io.Pipe()
cmdStdoutR, cmdStdoutW := io.Pipe()
cmdStderrR, cmdStderrW := io.Pipe()
ctx, cancelCmd := context.WithCancel(context.Background())
cmd := exec.CommandContext(ctx, cmdName, cmdArgs...)
cmd.Stdin = cmdStdinR
cmd.Stdout = cmdStdoutW
cmd.Stderr = cmdStderrW
if err := cmd.Start(); err != nil {
fmt.Println(err)
}
cmdStdinW.Close()
if err := cmd.Wait(); err != nil {
fmt.Println(err)
}
fmt.Println("DONE")
cancelCmd = cancelCmd
cmdStdoutR = cmdStdoutR
cmdStderrR = cmdStderrR
}
If you run this code and SIGKILL the bash process, go flags it as a
deadlock and panics. FWIW, this also happens if there are goroutines
monitoring cmdStdoutR and cmdStderrR.
What am I missing?
-- Salvatore
smile.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/CAEQs7S9mhLm7FZrKHoHuQUDk4BVk3ypFJVcCE%3D32y2-AMgwYWA%40mail.gmail.com.