diff --git a/linux/runtime.go b/linux/runtime.go index 1d747b0d7..494c6868d 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -201,10 +201,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts "id": id, "namespace": namespace, }).Warn("cleaning up after killed shim") - err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid) - if err == nil { - r.tasks.Delete(ctx, lc) - } else { + if err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid); err != nil { log.G(ctx).WithError(err).WithFields(logrus.Fields{ "id": id, "namespace": namespace, @@ -313,7 +310,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er } return nil, errdefs.FromGRPC(err) } - r.tasks.Delete(ctx, lc) + r.tasks.Delete(ctx, lc.id) if err := lc.shim.KillShim(ctx); err != nil { log.G(ctx).WithError(err).Error("failed to kill shim") } @@ -443,6 +440,7 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, ExitedAt: exitedAt, }) + r.tasks.Delete(ctx, id) if err := bundle.Delete(); err != nil { log.G(ctx).WithError(err).Error("delete bundle") } @@ -458,12 +456,10 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, } func (r *Runtime) terminate(ctx context.Context, bundle *bundle, ns, id string) error { - ctx = namespaces.WithNamespace(ctx, ns) rt, err := r.getRuntime(ctx, ns, id) if err != nil { return err } - if err := rt.Delete(ctx, id, &runc.DeleteOpts{ Force: true, }); err != nil { diff --git a/runtime/task_list.go b/runtime/task_list.go index 05f34c323..98fc90974 100644 --- a/runtime/task_list.go +++ b/runtime/task_list.go @@ -92,7 +92,7 @@ func (l *TaskList) AddWithNamespace(namespace string, t Task) error { } // Delete a task -func (l *TaskList) Delete(ctx context.Context, t Task) { +func (l *TaskList) Delete(ctx context.Context, id string) { l.mu.Lock() defer l.mu.Unlock() namespace, err := namespaces.NamespaceRequired(ctx) @@ -101,6 +101,6 @@ func (l *TaskList) Delete(ctx context.Context, t Task) { } tasks, ok := l.tasks[namespace] if ok { - delete(tasks, t.ID()) + delete(tasks, id) } } diff --git a/windows/runtime.go b/windows/runtime.go index 542c97363..d3721d4e3 100644 --- a/windows/runtime.go +++ b/windows/runtime.go @@ -195,7 +195,7 @@ func (r *windowsRuntime) Delete(ctx context.Context, t runtime.Task) (*runtime.E } wt.cleanup() - r.tasks.Delete(ctx, t) + r.tasks.Delete(ctx, t.ID()) r.publisher.Publish(ctx, runtime.TaskDeleteEventTopic,