Skip to content

Commit

Permalink
fix(executor): Tolerate docker re-creating containers. Fixes #6244 (#…
Browse files Browse the repository at this point in the history
…6252)

Signed-off-by: Alex Collins <alex_collins@intuit.com>
  • Loading branch information
alexec authored and sarabala1979 committed Jul 15, 2021
1 parent cd208e2 commit 7458115
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions workflow/executor/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,27 @@ func (d *DockerExecutor) Wait(ctx context.Context, containerNames []string) erro
log.WithError(err).Error("failed to poll container IDs")
}
}()
for !d.haveContainers(containerNames) {
for {
select {
case <-ctx.Done():
return ctx.Err()
default:
time.Sleep(1 * time.Second)
if d.haveContainers(containerNames) {
containerIDs, err := d.getContainerIDs(containerNames)
if err != nil {
return err
}
_, err = common.RunCommand("docker", append([]string{"wait"}, containerIDs...)...)
if err != nil && strings.Contains(err.Error(), "No such container") {
// e.g. reason could be ContainerCannotRun
log.WithError(err).Info("ignoring error as container may have been re-created and therefore container ID may have changed")
continue
}
return err
}
time.Sleep(time.Second)
}
}
containerIDs, err := d.getContainerIDs(containerNames)
if err != nil {
return err
}
_, err = common.RunCommand("docker", append([]string{"wait"}, containerIDs...)...)
return err
}

func (d *DockerExecutor) listContainers() (map[string]ctr, error) {
Expand Down Expand Up @@ -270,10 +277,6 @@ func (d *DockerExecutor) pollContainerIDs(ctx context.Context, containerNames []
log.Infof("ignoring container %q created at %v, too long before process started", containerName, c.createdAt)
continue
}
if c.status == "Created" && d.containers[containerName].status != "" {
log.Infof("ignoring created container %q that would %s -> %s", containerName, d.containers[containerName].status, c.status)
continue
}
d.containers[containerName] = c
log.Infof("mapped container name %q to container ID %q (created at %v, status %s)", containerName, c.containerID, c.createdAt, c.status)
}
Expand Down

0 comments on commit 7458115

Please sign in to comment.