containerd/containerd · error

failed to delete task: %w

Error message

failed to delete task: %w

What it means

If the sandbox task exists but is not running, recovery deletes it (t.Delete with WithProcessKill) to clean up leftover state. If Delete fails with a non-NotFound error, it is wrapped with this message. This leaves a dead task behind, preventing clean sandbox recovery and potentially blocking later container/sandbox teardown.

Source

Thrown at internal/cri/server/podsandbox/recover.go:138

			// Task does not exist, set sandbox state as NOTREADY.
			status.State = sandboxstore.StateNotReady
		} else {
			if taskStatus.Status == containerd.Running {
				exitCh, err := t.Wait(ctrdutil.NamespacedContext())
				if err != nil {
					if !errdefs.IsNotFound(err) {
						return status, channel, fmt.Errorf("failed to wait for sandbox container task: %w", err)
					}
					status.State = sandboxstore.StateNotReady
				} else {
					status.State = sandboxstore.StateReady
					status.Pid = t.Pid()
					channel = exitCh
				}
			} else {
				// Task is not running. Delete the task and set sandbox state as NOTREADY.
				if _, err := t.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
					return status, channel, fmt.Errorf("failed to delete task: %w", err)
				}
				status.State = sandboxstore.StateNotReady
			}
		}
		return status, channel, nil
	}()
	if err != nil {
		log.G(ctx).WithError(err).Errorf("Failed to load sandbox status for %q", cntr.ID())
	}

	// save it to cache in the podsandbox controller
	podSandbox := types.NewPodSandbox(cntr.ID(), s)
	podSandbox.Container = cntr
	if meta != nil {
		podSandbox.Metadata = *meta
	}
	podSandbox.Runtime = sandbox2.RuntimeOpts{
		Name:    info.Runtime.Name,

View on GitHub (pinned to 4246446a2b)

Solutions

  1. Read the wrapped error to see if the kill or the post-kill cleanup failed
  2. Check for processes stuck in D state (ps axo pid,stat,comm) and resolve underlying IO/storage issues
  3. Restart containerd; if the shim is orphaned, manually kill the shim process so the task can be removed
  4. Remove the stale sandbox container record so recovery and kubelet can recreate the pod
Defensive patterns

Strategy: try-catch

Try / catch

if _, err := t.Delete(ctx, containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
  log.Warnf("task delete failed for %s: %v", id, err)
  // check for D-state processes, kill orphaned shim, then retry once
}

Prevention

When it happens

Trigger: RecoverContainer startup: task status is not Running and t.Delete(ctx, WithProcessKill) returns a genuine error - shim failed to kill/remove the task, RPC error, or the underlying init process cannot be signaled.

Common situations: Zombie/unkillable process in the sandbox (e.g. stuck in uninterruptible D state); orphaned shim after reboot; shim binary/runtime mismatch preventing task cleanup after upgrade.

Related errors


AI-assisted analysis of containerd/containerd@4246446a2b (2026-09-02). Data as JSON: /api/errors/2a295edb3976eac1. Report an issue: GitHub.