Fix containerd task deletion after failed start
Deleting a containerd task whose status is Created fails with a "precondition failed" error. This is because (aside from Windows) a process is spawned when the task is created, and deleting the task while the process is running would leak the process if it was allowed. libcontainerd and the containerd plugin executor mistakenly try to clean up from a failed start by deleting the created task, which will always fail with the aforementined error. Change them to pass the `WithProcessKill` delete option so the cleanup has a chance to succeed. Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
9899820a17
commit
1bef9e3fbf
2 changed files with 4 additions and 2 deletions
|
@ -233,7 +233,9 @@ func (c *container) Start(ctx context.Context, checkpointDir string, withStdin b
|
||||||
stdinCloseSync <- t
|
stdinCloseSync <- t
|
||||||
|
|
||||||
if err := t.Start(ctx); err != nil {
|
if err := t.Start(ctx); err != nil {
|
||||||
if _, err := t.Delete(ctx); err != nil {
|
// Only Stopped tasks can be deleted. Created tasks have to be
|
||||||
|
// killed first, to transition them to Stopped.
|
||||||
|
if _, err := t.Delete(ctx, containerd.WithProcessKill); err != nil {
|
||||||
c.client.logger.WithError(err).WithField("container", c.c8dCtr.ID()).
|
c.client.logger.WithError(err).WithField("container", c.c8dCtr.ID()).
|
||||||
Error("failed to delete task after fail start")
|
Error("failed to delete task after fail start")
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ type c8dPlugin struct {
|
||||||
// deleteTaskAndContainer deletes plugin task and then plugin container from containerd
|
// deleteTaskAndContainer deletes plugin task and then plugin container from containerd
|
||||||
func (p c8dPlugin) deleteTaskAndContainer(ctx context.Context) {
|
func (p c8dPlugin) deleteTaskAndContainer(ctx context.Context) {
|
||||||
if p.tsk != nil {
|
if p.tsk != nil {
|
||||||
if _, err := p.tsk.Delete(ctx); err != nil && !errdefs.IsNotFound(err) {
|
if err := p.tsk.ForceDelete(ctx); err != nil && !errdefs.IsNotFound(err) {
|
||||||
p.log.WithError(err).Error("failed to delete plugin task from containerd")
|
p.log.WithError(err).Error("failed to delete plugin task from containerd")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue