mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Remove Run race condition
This commit is contained in:
parent
c106ed32ea
commit
2b6ca38728
1 changed files with 6 additions and 27 deletions
29
commands.go
29
commands.go
|
@ -1261,16 +1261,6 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
fmt.Fprintln(os.Stderr, "WARNING: ", warning)
|
||||
}
|
||||
|
||||
splitStderr := !config.Tty
|
||||
|
||||
connections := 0
|
||||
if config.AttachStdin || config.AttachStdout || (!splitStderr && config.AttachStderr) {
|
||||
connections += 1
|
||||
}
|
||||
if splitStderr && config.AttachStderr {
|
||||
connections += 1
|
||||
}
|
||||
|
||||
//start the container
|
||||
_, _, err = cli.call("POST", "/containers/"+out.ID+"/start", nil)
|
||||
if err != nil {
|
||||
|
@ -1279,19 +1269,12 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
|
||||
if !config.AttachStdout && !config.AttachStderr {
|
||||
fmt.Println(out.ID)
|
||||
}
|
||||
if connections > 0 {
|
||||
chErrors := make(chan error, connections)
|
||||
} else {
|
||||
chErrors := make(chan error)
|
||||
if config.Tty {
|
||||
cli.monitorTtySize(out.ID)
|
||||
}
|
||||
|
||||
if splitStderr && config.AttachStderr {
|
||||
go func() {
|
||||
chErrors <- cli.hijack("POST", "/containers/"+out.ID+"/attach?logs=1&stream=1&stderr=1", config.Tty, nil, os.Stderr)
|
||||
}()
|
||||
}
|
||||
|
||||
v := url.Values{}
|
||||
v.Set("logs", "1")
|
||||
v.Set("stream", "1")
|
||||
|
@ -1302,20 +1285,16 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
if config.AttachStdout {
|
||||
v.Set("stdout", "1")
|
||||
}
|
||||
if !splitStderr && config.AttachStderr {
|
||||
if config.AttachStderr {
|
||||
v.Set("stderr", "1")
|
||||
}
|
||||
go func() {
|
||||
chErrors <- cli.hijack("POST", "/containers/"+out.ID+"/attach?"+v.Encode(), config.Tty, os.Stdin, os.Stdout)
|
||||
}()
|
||||
for connections > 0 {
|
||||
err := <-chErrors
|
||||
if err != nil {
|
||||
if err := <-chErrors; err != nil {
|
||||
utils.Debugf("Error hijack: %s", err)
|
||||
return err
|
||||
}
|
||||
connections -= 1
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue