Skip to content

Report container bundle cleanup failures instead of hiding them - #2574

Open
HeZ2z wants to merge 1 commit into
apple:mainfrom
HeZ2z:fix/prune-reporting
Open

HeZ2z wants to merge 1 commit into
apple:mainfrom
HeZ2z:fix/prune-reporting

Conversation

@HeZ2z

@HeZ2z HeZ2z commented Nov 27, 2026

Copy link
Copy Markdown

Closes #2573.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

container delete and container prune reported success even when the container bundle could not be removed from disk. ContainersService._cleanUp treated bundle deletion as best effort: it logged a warning and then removed the container from the in-memory state unconditionally, so the API returned success. The CLI then printed the container ID and reported reclaimed disk space while the data was still on disk and no longer reachable through any container command.

Reproduced by making the bundle read-only:

chmod -R a-w "$HOME/Library/Application Support/com.apple.container/containers/prune-victim"
container prune; echo "exit=$?"
prune-victim
Reclaimed 4 KB in disk space
exit=0

The bundle directory was still present afterwards and container ls -a no longer listed the container, leaving the directory only removable by hand.

What changed

  • ContainersService._cleanUp captures a bundle deletion failure and throws ContainerizationError(.internalError, message: "failed to delete bundle for container <id> at <path>: <cause>") after removing the container from the state map. The container is not usable either way, but the caller learns that data remains and the message names the path.
  • ContainerPrune counts disk usage only after a successful delete, accumulates failures, and ends with failed to prune one or more containers: [...] and a non-zero exit. "Reclaimed" is only logged when at least one container was pruned.
  • Adds testDeleteReportsBundleCleanupFailure to TestCLIPruneCommandSerial: it creates a container, clears the write bits on its bundle directory, and asserts that container delete exits non-zero and names the bundle in the error. The bundle path is resolved from container system status --format json (paths.appRoot), so the test does not depend on runner environment variables.

Behavior change

delete previously never failed due to cleanup problems. It now fails when the bundle cannot be removed, while the container still leaves the state store. I chose this over keeping the record (which would make a logically deleted container keep showing up in container ls -a); happy to switch if the best-effort semantics were intentional.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

Manual verification with a debug build of this branch:

Before (main):

$ container prune; echo "exit=$?"
prune-victim
Reclaimed 4 KB in disk space
exit=0
$ ls -d .../containers/prune-victim    # still present

After:

$ container prune; echo "exit=$?"
failed to prune container: ["id": prune-victim, "error": internalError: "failed to delete container"
  (cause: "internalError: "failed to delete bundle for container prune-victim at
  /.../containers/prune-victim: ... Permission denied ...")"]
Error: failed to prune one or more containers: ["prune-victim"]
exit=1

Normal prune (no permission failure) still prints the removed containers and reclaims space as before, and container delete on a normal container is unchanged.

The new integration test fails against an apiserver built from main (result.status != 0) and passes with this branch.

`container delete` and `container prune` returned success when the bundle directory could not be removed, because `ContainersService._cleanUp` logged the failure and then dropped the container from state unconditionally. The caller had no way to know the data was still on disk.

Capture the bundle deletion error, keep removing the container from state, and rethrow so `delete` and `prune` surface it. `prune` now counts reclaimed space only for containers it actually removed, aggregates failures, and exits non-zero.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container delete and prune report success when the container bundle cannot be removed

1 participant