From 1e0f2186a985368f7133768b31eb6c288ba54691 Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Wed, 2 Nov 2022 13:48:13 -0400 Subject: [PATCH] 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 mistakenly tries to clean up from a failed start by deleting the created task, which will always fail with the aforementioned error. Change it to pass the `WithProcessKill` delete option so the cleanup has a chance to succeed. Signed-off-by: Cory Snider (cherry picked from commit 1bef9e3fbfbcedce10f476f890961fd1ba574fbb) Signed-off-by: Cory Snider --- libcontainerd/remote/client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libcontainerd/remote/client.go b/libcontainerd/remote/client.go index a2b895b328..5278d4a974 100644 --- a/libcontainerd/remote/client.go +++ b/libcontainerd/remote/client.go @@ -245,7 +245,9 @@ func (c *client) Start(ctx context.Context, id, checkpointDir string, withStdin close(stdinCloseSync) 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.logger.WithError(err).WithField("container", id). Error("failed to delete task after fail start") }