Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #154 from thaJeztah/18.09_backport_fix_stale_conta…
Browse files Browse the repository at this point in the history
…iner_on_start

[18.09 backport] Delete stale containerd object on start failure
  • Loading branch information
andrewhsu authored Feb 22, 2019
2 parents 24c6c3e + 1d03535 commit ba8664c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,22 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
return err
}

err = daemon.containerd.Create(context.Background(), container.ID, spec, createOptions)
ctx := context.TODO()

err = daemon.containerd.Create(ctx, container.ID, spec, createOptions)
if err != nil {
return translateContainerdStartErr(container.Path, container.SetExitCode, err)
if errdefs.IsConflict(err) {
logrus.WithError(err).WithField("container", container.ID).Error("Container not cleaned up from containerd from previous run")
// best effort to clean up old container object
daemon.containerd.DeleteTask(ctx, container.ID)
if err := daemon.containerd.Delete(ctx, container.ID); err != nil && !errdefs.IsNotFound(err) {
logrus.WithError(err).WithField("container", container.ID).Error("Error cleaning up stale containerd container object")
}
err = daemon.containerd.Create(ctx, container.ID, spec, createOptions)
}
if err != nil {
return translateContainerdStartErr(container.Path, container.SetExitCode, err)
}
}

// TODO(mlaventure): we need to specify checkpoint options here
Expand Down

0 comments on commit ba8664c

Please sign in to comment.