-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAge
Milestone
Description
Here is code from golang-nuts:
cmd := exec.Command("cat")
in, _ := cmd.StdinPipe()
out, _ := cmd.StdoutPipe()
cmd.Start()
go func() { defer os.Stdout.Close(); io.Copy(os.Stdout, out) }()
go func() { defer in.Close(); io.Copy(in, os.Stdin) }()
cmd.Wait()
https://groups.google.com/forum/#!topic/golang-nuts/gjkbC6M4cAU
This has 2 data races:
1. Both cmd and user close 'in'.
2. Cmd closes 'out', while user reads from it.
I've seen similar races in several projects.
os/exec documentation must clearly explain:
1. When it is allowed to close stdin/stdout (only after Wait?)
2. How to stream stdout (it's easy to race with stdout.Close in Wait)
3. How to close stdin to notify the process about end of input data (e.g. cat)
4. How/when to use thread-safe Reader/Writer
It all is basically impossible to get right first time.Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAge