From 351a51242e659ac50114f2268a99cfec6ed381fd Mon Sep 17 00:00:00 2001 From: ningmingxiao Date: Fri, 29 May 2026 16:06:20 +0800 Subject: [PATCH] fix container can't be started when task status is created Signed-off-by: ningmingxiao --- pkg/containerutil/containerutil.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/containerutil/containerutil.go b/pkg/containerutil/containerutil.go index fc17995dff9..9f036e44164 100644 --- a/pkg/containerutil/containerutil.go +++ b/pkg/containerutil/containerutil.go @@ -258,8 +258,25 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i } if oldTask, err := container.Task(ctx, nil); err == nil { + if status, err := oldTask.Status(ctx); err == nil { + if status.Status == containerd.Created { + sig, err := signal.ParseSignal("SIGKILL") + if err != nil { + return err + } + err = oldTask.Kill(ctx, sig) + if err != nil { + return err + } + statusC, err := oldTask.Wait(ctx) + if err != nil { + return err + } + <-statusC + } + } if _, err := oldTask.Delete(ctx); err != nil { - log.G(ctx).WithError(err).Debug("failed to delete old task") + log.G(ctx).WithError(err).Error("failed to delete old task") } } detachC := make(chan struct{})