fix(delete): treat podman cgroup race as pod-already-gone (issue #71) - #101
Merged
Conversation
DELETE returned 500 and left a resurrectable phantom store record plus a leaked scheduler/GPU reservation when podman pod rm hit "cgroup: Unit machine-libpod_pod_<id>.slice not loaded" -- a benign race where the pod's containers were already torn down by the preceding stop and systemd/crun reaped the pod's cgroup slice before rm got to it. The desired end state (pod gone) was already true, but the error text didn't match isNoSuchPod so it fell through to a 500. Classify it the same way isNoSuchPod already is: isCgroupCleanupRace matches the cgroup/not-loaded text, isPodAlreadyGone combines it with isNoSuchPod, and every DELETE-path check that used isNoSuchPod now uses isPodAlreadyGone. Add a bounded retry (removePodWithRetry, up to 3 attempts) around the RemovePod call specifically for this race -- the issue's own repro shows an immediate retry of pod rm typically succeeds outright once the race window passes. The existing issue #81 podConfirmedGone fallback is untouched as the catch-all for genuinely unclassified remove errors. fixes #71
Mirrors the internal/api fix for the same issue #71 race in the req.spark.delete NATS handler: podman pod rm's benign "cgroup: Unit machine-libpod_pod_<id>.slice not loaded" error is now classified via isPodAlreadyGone (isNoSuchPod OR isCgroupCleanupRace) instead of isNoSuchPod alone, and the RemovePod call goes through a bounded removePodWithRetry (up to 3 attempts) before falling through to the existing issue #81 status-confirmation fallback. refs #71
This was referenced Aug 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #71:
DELETE /api/v1/pods/{name}(and the equivalentreq.spark.deleteNATS handler) returned a 500 and left a resurrectable phantom store record plus a leaked scheduler/GPU reservation wheneverpodman pod rmhitcgroup: Unit machine-libpod_pod_<id>.slice not loaded. This is a benign podman race, not a real failure: the pod's containers were already torn down by the preceding stop, and systemd/crun reaped the pod's cgroup slice beforermgot to it, so the desired end state (pod gone) was already true — podman just reports the absence of the thing it's cleaning up as a hard error. An earlier occurrence of exactly this left a pod that resurrected across the next upgrade, because the persisted "Running" record was re-adopted at startup.Changes
internal/api/pods_mutate.go: addedisCgroupCleanupRace(err)(matches the lowercased error text containing bothcgroupandnot loaded) andisPodAlreadyGone(err)(isNoSuchPod(err) || isCgroupCleanupRace(err)). Every DELETE-path check that used to gate onisNoSuchPodalone (StopPod's error, RemovePod's error, and the issue GPU reservation leaks: scheduler reports 0 GPUs free while the device is physically idle and no live pod holds it #81podConfirmedGonestatus-check fallback) now gates onisPodAlreadyGone, so the cgroup race is classified exactly the same way "no such pod" already is: proceed with store/scheduler cleanup instead of aborting.internal/bus/handler_delete.go: the identical fix for the NATS handler, using its own private copy of the same helpers (this package already kept its ownisNoSuchPodrather than sharing one across the import boundary, per the existing comment there — same pattern continued).removePodWithRetry(a fixed cap of 3 attempts, 20ms apart), retrying theRemovePodcall specifically when the error isisCgroupCleanupRace— the issue's own repro showed an immediate manual retry ofpodman pod rmsucceeding outright once the race window passed, so this gives podman a real chance to finish removing the pod rather than only papering over the classification. Retrying "no such pod" or any other error is skipped: it can't change the outcome and would only add latency.podConfirmedGone/status-check fallback (it stays as the catch-all for genuinely unclassified remove errors — seeTestDeletePodRemoveFails/TestDeleteHandler'sremove_errorcase, both still passing), andinternal/reconciler/reconciler.go's separate, pre-existingisNoSuchPodcopy (different subsystem, out of scope for this issue).Testing
go build ./...,go vet ./...,staticcheck ./...— all clean.go test ./... -race -timeout 120s -count=1— all 13 packages pass, no regressions.-vto see the actual--- PASS:line):internal/api/pods_mutate_test.go:TestDeletePodCgroupRaceTreatedAsSuccess(everyRemovePodattempt returns the cgroup-race error; retries exhaust; DELETE still returnsdeleted:true, store record and scheduler reservation gone) andTestDeletePodCgroupRaceRetrySucceeds(errors on the firstRemovePodcall, succeeds on the retried second call; assertsRemovePodwas called exactly twice).internal/bus/handler_delete_test.go:TestDeleteHandler_CgroupRaceTreatedAsSuccessandTestDeleteHandler_CgroupRaceRetrySucceeds, mirroring the two above for the NATS handler.TestDeletePodRemoveFails,TestDeleteHandler'sremove_errorandremove_error_but_pod_confirmed_gonesubtests) to confirm the existing fallback for unrelated remove errors still returns an error/500 and wasn't weakened by the broaderisPodAlreadyGoneclassification.t4-1-issue71-delete-race, 5 predicates:cap-api-t41,cap-api-t42,cap-bus-t41,cap-bus-t42,guard-suite) — predicates confirmed red at t0 before any code existed, and all 5 pass now (cross-verified withkazi apply --check --json, not just the higher-level convergence report).Risk & rollback
Low risk: purely additive error classification plus a bounded, short retry — no changes to the existing "no such pod" handling or the issue #81 fallback's own logic. Revert is a straight
git revertof the two commits if needed.Linked issues / tasks
podman pod rmhits a cgroup-cleanup-race error).