Skip to content

os/exec: stop stdin copying goroutine after process exits #7990

@gopherbot

Description

@gopherbot

by robryk:

When Cmd.Stdin is not a file, Cmd.Wait waits until a read on it unblocks. When Cmd.Stdin
is a file, Cmd.Wait returns immediately after the command being executed completes. I
find it confusing that semantics of Wait depend on the kind of Reader passed as standard
input.

What does 'go version' print?
go version devel +96cbc91bc15a Sat Apr 26 22:31:32 2014 -0700 + linux/amd64

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1. Run http://play.golang.org/p/eADuSYGZ1C. Notice that it exits
   immediately.
2. Run http://play.golang.org/p/hh1eXk9S0E. Notice that it waits
   (in Cmd.Wait) for EOF on stdin.

What happened?

These two programs differ in behaviour.

What should have happened instead?

These two programs should behave identically, because the Reader passed
to Cmd.Stdin behaves identically in both cases.

Please provide any additional information below.

I find the behaviour for non-files troublesome to work with, although it seems to
conform better to the documentation. In my usecase, I need to close the stdin Reader
after the process has exited (the Reader can have a user on the other end, so I can't
predict that the input has ended). Alas, I can't use Wait() for that purpose, because
Wait() waits until my reader unblocks, which (assuming no input is forthcoming) will
happen only after it is closed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions