Skip to content

Commit fdd21d6

Browse files
committed
fix container can't be started when task status is created
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
1 parent 89ecd85 commit fdd21d6

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

pkg/containerutil/containerutil.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,26 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
256256
log.G(ctx).Warnf("container %s is already running", container.ID())
257257
return nil
258258
}
259-
260259
if oldTask, err := container.Task(ctx, nil); err == nil {
260+
if status, err := oldTask.Status(ctx); err == nil {
261+
if status.Status == containerd.Created {
262+
sig, err := signal.ParseSignal("SIGKILL")
263+
if err != nil {
264+
return err
265+
}
266+
err = oldTask.Kill(ctx, sig)
267+
if err != nil {
268+
return err
269+
}
270+
statusC, err := oldTask.Wait(ctx)
271+
if err != nil {
272+
return err
273+
}
274+
<-statusC
275+
}
276+
}
261277
if _, err := oldTask.Delete(ctx); err != nil {
262-
log.G(ctx).WithError(err).Debug("failed to delete old task")
278+
log.G(ctx).WithError(err).Errorf("failed to delete old task")
263279
}
264280
}
265281
detachC := make(chan struct{})

0 commit comments

Comments
 (0)