Preserve unloadable bundles and write metadata atomically - #2035
Open
stephenlclarke wants to merge 2 commits into
Open
Preserve unloadable bundles and write metadata atomically#2035stephenlclarke wants to merge 2 commits into
stephenlclarke wants to merge 2 commits into
Conversation
Keep container bundles on disk when startup loading fails and write bundle metadata atomically. Validate runtime availability before publishing an in-memory container state so preserved bundles are not exposed as usable until their runtime is available. Add regression coverage for malformed metadata and missing runtime plugins. Upstream-PR: apple#1859 Upstream-Head: f99feb3
Populate both current and legacy configuration files with malformed JSON so startup recovery reaches a decoding failure instead of stopping at a missing fallback file.
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.
During testing of my Container Compose plugin, I found that startup load failures can delete complete container bundles and, when a runtime plugin is missing, still publish an unusable in-memory state for the deleted bundle.
This supersedes and credits @radheradhe01's work in #1859. That PR correctly preserves failed bundles and makes the generic bundle writer atomic. This version retains those fixes and strengthens them by:
ContainerState;rootfs.jsonwrites atomic as well as metadata written through the generic bundle writer; andFixes #2033.
Type of Change
Motivation and Context
ContainersService.loadAtBootcurrently removes a bundle directory for every load error. Some failures are transient, such as a runtime plugin not being registered when startup loading runs, while malformed metadata should remain available for diagnosis or recovery.The missing-runtime path also constructs and inserts a stopped
ContainerStatebefore checking for the plugin. The subsequent error deletes the bundle, but the returned dictionary still exposes the state as a usable container.Bundle JSON is currently written directly to its destination. An interrupted write can therefore expose truncated metadata on the next startup, which then reaches the destructive load-error path.
rootfs.jsonuses a separate writer and must receive the same atomic replacement semantics.Reproduction on stock
mainTested at
48145ac7fb177d9fb14e015a0bdea4c642b36729.config.jsonand the legacy fallbackruntime-configuration.json.ContainersService.loadAtBoot.loadAtBootagain.The corrected regression suite fails on stock
mainwith four issues:config.jsonfails withNSCocoaErrorDomain Code=260.Expected behaviour
Failed bundles remain on disk, no state is inserted until runtime availability is validated, and all bundle metadata files are replaced atomically.
Testing
Tested locally
Added/updated tests
Added/updated docs
make check: passedswift test --filter ContainerLoadAtBootTests: 2 tests in 1 suite passed in 0.006 seconds, 201.58 seconds including the initial dependency buildmake test: 591 tests in 72 suites passed in 2.011 seconds, 119.33 seconds including the Apple test buildStrict-review focused rerun:
swift test --filter ContainerLoadAtBootTestspassed 2 tests in 1 suite in 0.006 seconds, 95.93 seconds including a clean rebuildTwo fresh strict-review full-suite retries passed the persistence coverage, then stopped on the unrelated stock
DirectoryWatcherTestreadiness races corrected by Close directory watcher descriptors after failed startup #2036 (testWatchingNonExistingDirectory, thentestWatchingNonExistingParent)Stock
mainnegative control: the same 2 tests failed with the four expected issues in 0.016 seconds, 94.56 seconds including rebuildgit diff --check: passedAll commits are signed and verified.