From 74ed6f150166019645725447ecab0535a0147e64 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Mon, 17 Jun 2013 14:44:35 -0700 Subject: [PATCH 1/2] - Runtime: Fixes #884 enforce stdout/err sync by merging the stream Upstream-commit: 3a0ffbc77267e395676860db265ee3476c45b3c2 Component: engine --- components/engine/commands.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index ce15fd6cf1..abe91f6eab 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1058,37 +1058,23 @@ func (cli *DockerCli) CmdAttach(args ...string) error { return err } - splitStderr := container.Config.Tty - - connections := 1 - if splitStderr { - connections += 1 - } - chErrors := make(chan error, connections) + chErrors := make(chan error) if container.Config.Tty { cli.monitorTtySize(cmd.Arg(0)) } - if splitStderr { - go func() { - chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?stream=1&stderr=1", false, nil, os.Stderr) - }() - } + v := url.Values{} v.Set("stream", "1") v.Set("stdin", "1") v.Set("stdout", "1") - if !splitStderr { - v.Set("stderr", "1") - } + v.Set("stderr", "1") + go func() { chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) }() - for connections > 0 { - err := <-chErrors - if err != nil { - return err - } - connections -= 1 + + if err := <-chErrors; err != nil { + return err } return nil } From ec13f22dbd785cbefbd9fb47b8427f1b2373b38e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 18 Jun 2013 10:10:03 -0700 Subject: [PATCH 2/2] Remove useless goroutine Upstream-commit: 3dc93e390ad3d310dede84948b726ce67e261375 Component: engine --- components/engine/commands.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/components/engine/commands.go b/components/engine/commands.go index abe91f6eab..19fb32f966 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1058,7 +1058,6 @@ func (cli *DockerCli) CmdAttach(args ...string) error { return err } - chErrors := make(chan error) if container.Config.Tty { cli.monitorTtySize(cmd.Arg(0)) } @@ -1069,11 +1068,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error { v.Set("stdout", "1") v.Set("stderr", "1") - go func() { - chErrors <- cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout) - }() - - if err := <-chErrors; err != nil { + if err := cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), container.Config.Tty, os.Stdin, os.Stdout); err != nil { return err } return nil