Repository navigation
Force filesystem sync when unpacking container image layers - #4994
Conversation
containerd fsyncs its metadata database when committing a snapshot, but never syncs the unpacked layer data itself. On an unclean shutdown within the writeback window after an image pull this leaves layers with zero-byte files (correct names/modes/mtimes, no data) while the snapshot stays durably recorded as valid. Because existing snapshots are never re-verified or re-unpacked, such corruption even survives deleting and re-pulling the image, and with shared base layers it can only be recovered by wiping the Docker storage entirely. This is the failure signature behind a growing number of reports of broken plugins/add-ons/Core after power loss (e.g. 0-byte coredns in home-assistant/plugin-dns#207, supervisor#6476/#6835, #4913). Enable the containerd diff-service sync_fs option (containerd >= 2.0, containerd/containerd#10284): the daemon then issues one syncfs(2) per applied layer, making unpacked data as durable as the metadata that references it. It applies to all clients of the daemon, including dockerd with the containerd image store. Verified in QEMU on haos 18.3.dev (Docker 29.6.2, containerd 2.2.6): * With completely stock settings, a power cut <1s after `docker pull` of the DNS plugin image corrupts the image 2 out of 2 runs: one run zeroed /usr/bin/coredns entirely, the other zeroed the s6 scripts and left coredns truncated (20021248 of 25919650 bytes) - matching the two damage profiles reported in plugin-dns#207. * Deterministic A/B with kernel background writeback suppressed, so survival can only come from the stack syncing explicitly: without this option 1215 zero-byte files including a 0-byte coredns failing with "exec format error"; with sync_fs the image survives intact (152 kB dirty at the power cut vs 76 MB). * strace on containerd confirms 0 syncfs calls per image load before, one per layer after - which also confirms dockerd pulls route through the containerd daemon's diff service where this option takes effect. * Cost of loading+unpacking the 2 GB Core image: 41.6s -> 42.2s on a fast disk, 226s -> 230s (+1.9%) on a 30 MB/s / 250 IOPS throttled disk. Note QEMU throttling does not model SD-card sync latency, so the real-world cost on the slowest cards may be somewhat higher, but it stays bounded at one syncfs per layer. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. π βΉοΈ Recent review infoβοΈ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: π Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. π WalkthroughWalkthroughThe containerd diff service now enables ChangesContainerd durability
Estimated code review effort: 1 (Trivial) | ~2 minutes Merge Risk: βͺ Minimal Β· up to This localized configuration change enables filesystem synchronization for unpacked image layers, with no actionable merge-blocking risk remaining after normal checks and review. Poem
π₯ Pre-merge checks | β 5β Passed checks (5 passed)
Full details: Docstring CoverageExplanation No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.) β¨ Finishing Touchesπ§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Enables durable container image layer unpacking to reduce corruption after abrupt power loss.
Changes:
- Enables containerd diff-service
sync_fs. - Documents the corruption scenario and durability rationale.
π‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
docker load times (image tar on the data partition, per-cycle wiped store) Small image β DNS plugin, 5 layers, ~65 MB (isolates fixed per-layer sync cost): Big image β Core, ~10 layers, ~2 GB (throughput-dominated): The measurements appear to have quite some variance. While I've stopped all containers and removed the complete storage, page cache or other circumstances might have played a role. It is interesting that DNS has this higher increase. It could be just due to its small size. or it could be related to CoreDNS binary which is rather large and in the second to last layer (and rather often corrupts in real world). In general, the cost appears acceptable to me. |
sairon
left a comment
There was a problem hiding this comment.
Thanks for the tests, it doesn't look that bad, and if it helps with the corruptions we're seeing, the minor performance hit is acceptable for me - still better than nuking the whole Docker storage, which is the only other option we have.
Summary
Enable the containerd diff-service
sync_fsoption so the daemon issues onesyncfs(2)after each unpacked image layer. containerd fsyncs its metadata database when committing a snapshot, but never syncs the unpacked layer data itself β after an unclean shutdown shortly after an image pull this leaves layers with zero-byte files (correct names/modes/mtimes, no data) while the snapshot stays durably recorded as valid. Because committed snapshots are never re-verified or re-unpacked, the corruption even survives deleting and re-pulling the image (moby/moby#49784, containerd/containerd#8973), and with shared base layers it is only recoverable by wiping the Docker storage.This is the failure signature behind a growing number of corruption reports, e.g. the 0-byte coredns in home-assistant/plugin-dns#207, home-assistant/supervisor#6476, home-assistant/supervisor#6835, #4913. Upstream background: containerd/containerd#8895, fixed opt-in via containerd/containerd#10284 (containerd >= 2.0). The daemon-side option applies to all clients of the daemon, including dockerd with the containerd image store (the default since HAOS 17). Installs still on the overlay2 graphdriver unpack inside dockerd and are unaffected either way.
Verification (QEMU, HAOS 18.3.dev, Docker 29.6.2 / containerd 2.2.6)
docker pullof the DNS plugin image: corrupts 2/2 runs β one run zeroed/usr/bin/corednsentirely, the other zeroed the s6 scripts and left coredns truncated (20021248 of 25919650 bytes), matching the two damage profiles reported in plugin-dns#207.exec format error; withsync_fsthe image survives the identical power cut intact (152 kB dirty at the cut vs 76 MB).syncfscalls per image load before, exactly one per layer after β also confirming dockerd pulls route through the daemon's diff service where this option takes effect.syncfsper layer rather than per file.Given HAOS commonly runs on SD cards without a UPS, trading a slightly slower pull for image data that is actually on disk when the pull completes seems like the right default.
Related: home-assistant/supervisor#6555 (Docker storage reset, the recovery path for already-corrupted installs).
π€ Generated with Claude Code
Summary by CodeRabbit