{"record":{"id":"943430dd2791e80a","repo":"slimtoolkit/slim","slug":"container-terminated","errorCode":null,"errorMessage":"Container terminated","messagePattern":"Container terminated","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/app/master/command/debug/handle_kubernetes_runtime.go","lineNumber":1001,"sourceCode":"\n\terr := wait.PollImmediate(2*time.Second, 2*time.Minute, isPodRunning)\n\tif err != nil {\n\t\treturn nil, \"\", err\n\t}\n\n\treturn outputPod, podName, nil\n}\n\nconst (\n\tctInit      = \"init\"\n\tctStandard  = \"standard\"\n\tctEphemeral = \"ephemeral\"\n)\n\nvar (\n\tErrPodTerminated       = errors.New(\"Pod terminated\")\n\tErrPodNotRunning       = errors.New(\"Pod not running\")\n\tErrContainerTerminated = errors.New(\"Container terminated\")\n)\n\nfunc waitForContainer(\n\tlogger *log.Entry,\n\txc *app.ExecutionContext,\n\tctx context.Context,\n\tapi *kubernetes.Clientset,\n\tnsName string,\n\tpodName string,\n\tcontainerName string,\n\tcontainerType string) error {\n\tlogger.Tracef(\"waitForContainer(%s,%s,%s,%s)\", nsName, podName, containerName, containerType)\n\n\tisContainerRunning := func() (bool, error) {\n\t\tpod, err := api.CoreV1().Pods(nsName).Get(ctx, podName, metav1.GetOptions{})\n\t\tif err != nil {\n\t\t\treturn false, err\n\t\t}","sourceCodeStart":983,"sourceCodeEnd":1019,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/command/debug/handle_kubernetes_runtime.go#L983-L1019","documentation":"ErrContainerTerminated is returned from HandleKubernetesRuntime (and the debug runtime flow) when the specific container targeted for debugging has terminated. Even if the pod is running, an exited container cannot be attached to or instrumented.","triggerScenarios":"Selecting a container that exited before the debug attach; the target process crashes during waitForContainer; naming a sidecar/ephemeral container that already finished.","commonSituations":"Debugging an app container that crashed; wrong container name passed (e.g. an init container); short-lived containers that finish before the debugger connects.","solutions":["Check container state with kubectl describe pod and pick a currently running container name","Prevent the app from exiting during debugging or use an ephemeral debug container strategy","Re-run the debug command immediately after restarting the container"],"exampleFix":"kubectl debug -it my-pod --image=busybox --target=my-app  # debug via ephemeral container instead of attaching to the exited one","handlingStrategy":"validation","validationCode":"cs, _ := clientset.CoreV1().Pods(ns).Get(ctx, pod, metav1.GetOptions{})\nfor _, st := range cs.Status.ContainerStatuses {\n\tif st.Name == target && st.State.Running == nil {\n\t\treturn fmt.Errorf(\"container %s is not running\", target)\n\t}\n}","typeGuard":null,"tryCatchPattern":"// Go\nif errors.Is(err, ErrContainerTerminated) {\n\t// re-run with a running container or use kubectl debug ephemeral container\n}","preventionTips":["Verify the target container's state is Running before attaching","Don't target init or already-finished sidecar containers","Restart the workload if the app container keeps exiting"],"tags":["kubernetes","container","lifecycle"],"backgroundTag":"container-terminated","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}