Skip to content

os/exec: cmd.Wait does not return after process termination when stdin is attached #10338

@sykesm

Description

@sykesm

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())
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions