Skip to content

Commit c988e37

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 c988e37

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

pkg/containerutil/containerutil.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,35 @@ func Start(ctx context.Context, container containerd.Container, isAttach bool, i
258258
}
259259

260260
if oldTask, err := container.Task(ctx, nil); err == nil {
261+
if status, err := oldTask.Status(ctx); err == nil {
262+
if status.Status == containerd.Created {
263+
sig, err := signal.ParseSignal("SIGKILL")
264+
if err != nil {
265+
return err
266+
}
267+
err = oldTask.Kill(ctx, sig)
268+
if err != nil {
269+
return err
270+
}
271+
timeout := time.After(5 * time.Second)
272+
ticker := time.NewTicker(20 * time.Millisecond)
273+
defer ticker.Stop()
274+
for {
275+
select {
276+
case <-timeout:
277+
return fmt.Errorf("wait task stopped timeout")
278+
case <-ticker.C:
279+
taskstatus, err := oldTask.Status(ctx)
280+
if err != nil {
281+
return err
282+
}
283+
if taskstatus.Status == containerd.Stopped {
284+
return nil
285+
}
286+
}
287+
}
288+
}
289+
}
261290
if _, err := oldTask.Delete(ctx); err != nil {
262291
log.G(ctx).WithError(err).Debug("failed to delete old task")
263292
}

0 commit comments

Comments
 (0)