{"record":{"id":"ed1c94961acbd827","repo":"containerd/containerd","slug":"can-t-find-container-for-taskexit-event-w","errorCode":null,"errorMessage":"can't find container for TaskExit event: %w","messagePattern":"can't find container for TaskExit event: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cri/server/events.go","lineNumber":338,"sourceCode":"\n// HandleEvent handles a containerd event.\nfunc (ce *criEventHandler) HandleEvent(any any) error {\n\tctx := ctrdutil.NamespacedContext()\n\tctx, cancel := context.WithTimeout(ctx, handleEventTimeout)\n\tdefer cancel()\n\n\tswitch e := any.(type) {\n\tcase *eventtypes.TaskExit:\n\t\tlog.L.Infof(\"TaskExit event %+v\", e)\n\t\t// Use ID instead of ContainerID to rule out TaskExit event for exec.\n\t\tcntr, err := ce.c.containerStore.Get(e.ID)\n\t\tif err == nil {\n\t\t\tif err := ce.c.handleContainerExit(ctx, e, cntr, cntr.SandboxID); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to handle container TaskExit event: %w\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\t} else if !errdefs.IsNotFound(err) {\n\t\t\treturn fmt.Errorf(\"can't find container for TaskExit event: %w\", err)\n\t\t}\n\t\tsb, err := ce.c.sandboxStore.Get(e.ID)\n\t\tif err == nil {\n\t\t\tif err := ce.c.handleSandboxExit(ctx, sb, e.ExitStatus, e.ExitedAt.AsTime()); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to handle sandbox TaskExit event: %w\", err)\n\t\t\t}\n\t\t\treturn nil\n\t\t} else if !errdefs.IsNotFound(err) {\n\t\t\treturn fmt.Errorf(\"can't find sandbox for TaskExit event: %w\", err)\n\t\t}\n\t\treturn nil\n\tcase *eventtypes.SandboxExit:\n\t\tlog.L.Infof(\"SandboxExit event %+v\", e)\n\t\tsb, err := ce.c.sandboxStore.Get(e.GetSandboxID())\n\t\tif err == nil {\n\t\t\tif err := ce.c.handleSandboxExit(ctx, sb, e.ExitStatus, e.ExitedAt.AsTime()); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to handle sandbox TaskExit event: %w\", err)\n\t\t\t}","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/containerd/containerd/blob/4246446a2bf7d03837b0244118d858799393bd80/internal/cri/server/events.go#L320-L356","documentation":"HandleEvent returns this when a TaskExit event's container ID cannot be retrieved from the CRI container store with an error other than NotFound. NotFound is treated as benign (container already forgotten); other errors indicate the store lookup itself failed. Note the ID (not ContainerID) is used to exclude exec-process exits.","triggerScenarios":"containerStore.Get(e.ID) returns a non-NotFound error while dispatching *eventtypes.TaskExit — e.g. metadata DB failure, store corruption, or transport error.","commonSituations":"Bolt metadata DB contention or failure; containerd restart mid-event stream; corrupted container store after unclean shutdown.","solutions":["Check containerd logs for metadata store errors at the same time","Restart containerd to recover transient store failures","Let event backoff retry the event after transient failure","Run ctr c ls / crictl ps to verify store integrity after recovery"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: treat NotFound as benign, everything else needs investigation:\ncntr, err := containerStore.Get(e.ID)\nif err != nil {\n    if errdefs.IsNotFound(err) {\n        return nil\n    }\n    return fmt.Errorf(\"can't find container for TaskExit event: %w\", err)\n}","typeGuard":"func lookupFailed(err error) bool {\n    return err != nil && !errdefs.IsNotFound(err)\n}","tryCatchPattern":"if err := HandleEvent(ev); err != nil {\n    if lookupFailed(err) {\n        log.L.WithError(err).Errorf(\"store lookup failure; daemon health check needed\")\n        monitor.Backoff(id, ev)\n    }\n}","preventionTips":["Monitor bolt DB health and avoid IO starvation of the containerd root dir","Verify store integrity after unclean containerd shutdowns","Treat only NotFound as ignorable; retry other lookup failures via backoff","Check for containerd version upgrade inconsistencies in store contents"],"tags":["containerd","cri","store-lookup","event-handling"],"backgroundTag":"container-store-lookup-failed","analyzedSha":"4246446a2bf7d03837b0244118d858799393bd80","analyzedAt":"2026-09-02T00:14:43.053Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}