From 10e10c9573a0f20243212192fa782feb35651b18 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 22 Oct 2013 15:01:06 -0700 Subject: [PATCH] fix race condition in docker build with verbose + cleanup hostIntegration debug --- buildfile.go | 13 ++++++++++--- container.go | 9 +++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/buildfile.go b/buildfile.go index 8231287eaf..6aae0469cf 100644 --- a/buildfile.go +++ b/buildfile.go @@ -378,15 +378,22 @@ func (b *buildFile) run() (string, error) { c.Path = b.config.Cmd[0] c.Args = b.config.Cmd[1:] + var errCh chan error + + if b.verbose { + errCh = utils.Go(func() error { + return <-c.Attach(nil, nil, b.out, b.out) + }) + } + //start the container hostConfig := &HostConfig{} if err := c.Start(hostConfig); err != nil { return "", err } - if b.verbose { - err = <-c.Attach(nil, nil, b.out, b.out) - if err != nil { + if errCh != nil { + if err := <-errCh; err != nil { return "", err } } diff --git a/container.go b/container.go index c2188be625..01d442fed0 100644 --- a/container.go +++ b/container.go @@ -1,6 +1,7 @@ package docker import ( + "bytes" "encoding/json" "errors" "flag" @@ -847,15 +848,15 @@ func (container *Container) Start(hostConfig *HostConfig) (err error) { // Note: The container can run and finish correctly before // the end of this loop for now := time.Now(); time.Since(now) < 5*time.Second; { - // If the container dies while waiting for it, just reutrn + // If the container dies while waiting for it, just return if !container.State.Running { return nil } - output, err := exec.Command("lxc-info", "-n", container.ID).CombinedOutput() + output, err := exec.Command("lxc-info", "-s", "-n", container.ID).CombinedOutput() if err != nil { utils.Debugf("Error with lxc-info: %s (%s)", err, output) - output, err = exec.Command("lxc-info", "-n", container.ID).CombinedOutput() + output, err = exec.Command("lxc-info", "-s", "-n", container.ID).CombinedOutput() if err != nil { utils.Debugf("Second Error with lxc-info: %s (%s)", err, output) return err @@ -865,7 +866,7 @@ func (container *Container) Start(hostConfig *HostConfig) (err error) { if strings.Contains(string(output), "RUNNING") { return nil } - utils.Debugf("Waiting for the container to start (running: %v): %s\n", container.State.Running, output) + utils.Debugf("Waiting for the container to start (running: %v): %s", container.State.Running, bytes.TrimSpace(output)) time.Sleep(50 * time.Millisecond) }