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.
Issue #, if available:
nerdctl images rmito remove images, fscache is not cleaned upDescription of changes:
This patch implements explicit resource lifecycle management with immediate eviction support to fix resource leaks during unmount operations.
The core change enhances the LRU cache to support both deferred and immediate eviction modes. The
donecallback now accepts a boolean parameter:falsefor lazy cleanup andtruefor immediate removal. When immediate eviction is requested, cache entries are finalized and removed synchronously instead of waiting for LRU eviction.A new
Close()method is introduced alongside the existingDone()to distinguish between normal resource release and unmount scenarios. During filesystem unmount, layers callClose()to trigger immediate resource eviction, preventing the resource leaks observed in the original issue. Error paths are also updated to use immediate eviction for invalid or corrupted resources, ensuring they don't occupy cache space.Additionally, the patch adds explicit cleanup of span manager resources in the reader's
Close()method and improves snapshot restoration robustness by pre-creating required directories before mount operations. Overall, this provides deterministic cleanup timing with clear "release when convenient" vs. "release immediately" semantics, which is critical for proper resource management during unmounts and error handling. and error handling.Testing performed:
Observed:
nerdctl images -q | xargs nerdctl rmi -f Untagged: env12.com/ocs9:soci@sha256:979fe973858c87e1fb2152a9b17563f6fc59abc5c2f85293d15a7c827bbb6a02 Deleted: sha256:3a6ef9931f24a0ccd89e429366e0341d81b58d97bf7115612494f4249dd8d351Observed:
Observed:
Observed:
Observed:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.