You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: