Skip to content

Commit

Permalink
Merge pull request moby#2341 from dotcloud/1327-race_build_verbose-fix
Browse files Browse the repository at this point in the history
fix race condition in docker build with verbose + cleanup hostIntegration debug
  • Loading branch information
Victor Vieux committed Oct 22, 2013
2 parents b73065a + 10e10c9 commit 8ff7b70
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 10 additions & 3 deletions buildfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
9 changes: 5 additions & 4 deletions container.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package docker

import (
"bytes"
"encoding/json"
"errors"
"flag"
Expand Down Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit 8ff7b70

Please sign in to comment.