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 Jul 1, 2021
1 parent fa4b32a commit c9246d3
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 @@ -198,20 +198,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 @@ -271,10 +278,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 c9246d3

Please sign in to comment.