Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a race in the EROFS snapshotter where createSnapshot could create a snapshots/new-* staging directory before acquiring the metadata writer transaction, allowing a concurrent snapshot cleanup/remove to treat it as an orphan and delete it mid-flight. The change moves staging directory creation under the existing metadata writer transaction to ensure the on-disk staging directory and snapshot metadata lifecycle are serialized consistently.
Changes:
- Move
prepareDirectory(...)into thems.WithTransaction(..., true, ...)writer transaction increateSnapshot. - Ensure the
new-*staging directory is created immediately beforestorage.CreateSnapshot, preventing concurrent orphan cleanup from removing it.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
hi Chris @cayoub-oai , I am not sure how to parse how a unrelated Leaving |
|
Sorry for the confusion - hopefully this helps clarify. The key detail is that The race is:
You are right that this change lengthens the writer transaction; that is the trade-off used here to close the untracked-directory window. |
|
I guess we could just exclude the directory names starting with |
|
The worst case is that we could cleanup all directories starting with |
A new-* directory can exist before createSnapshot acquires the metadata writer transaction. A concurrent Remove performs a global orphan scan and can delete the staging directory because it is not in the ID map yet. Exclude new-* staging directories from orphan cleanup and use a shared local constant for directory creation and filtering. Signed-off-by: Chris Ayoub <[email protected]>
9ccc43c to
e940b5a
Compare
|
@hsiangkao updated - let me know what you think |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
plugins/snapshots/erofs/erofs.go:901
- Skipping all directories with the temp prefix here prevents orphan cleanup from ever reclaiming crash-leftover staging directories, and it diverges from the PR description (“move prepareDirectory into the writer transaction” / “does not special-case new-*”). Since erofs.createSnapshot still creates the temp dir before acquiring the writer transaction (plugins/snapshots/erofs/erofs.go:618), this check is acting as a workaround but changes cleanup semantics.
Consider aligning with the overlay snapshotter by moving prepareDirectory (and snapshotDir computation) inside the existing ms.WithTransaction(..., true, ...) in createSnapshot (overlay does this at plugins/snapshots/overlay/overlay.go:454-462). If you do that, this special-casing can be removed and orphan cleanup can continue to reclaim abandoned temp dirs.
// A new-* directory may belong to a concurrent snapshot creation. It is
// renamed to its metadata ID after the writer transaction is acquired, so
// Remove must not treat it as an orphan in the meantime.
if strings.HasPrefix(d, snapshotTempDirPrefix) {
continue
plugins/snapshots/erofs/erofs_linux_test.go:128
- This test codifies the behavior that
new-*staging directories are never considered for cleanup. That implies a staging directory left behind by a crashed process will not be reclaimed by subsequent orphan cleanup (sincegetCleanupDirectoriesis only used byRemovein this snapshotter).
If the intended fix is to avoid cleanup races without leaking temp dirs, prefer moving temp-dir creation into the writer transaction (like the overlay snapshotter) and update this test to assert that an unowned temp dir is returned for cleanup (i.e., it’s treated like any other orphan).
_, err = os.MkdirTemp(snapshotDir, snapshotTempDirPrefix)
require.NoError(t, err)
|
/cherry-pick release/2.3 |
|
/cherry-pick release/2.2 |
|
@hsiangkao: #13932 failed to apply on top of branch "release/2.3": DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
@hsiangkao: #13932 failed to apply on top of branch "release/2.2": DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Summary
Exclude in-flight EROFS
new-*staging directories from orphan cleanup duringsnapshot removal.
This prevents a concurrent
Removefrom deleting a directory thatcreateSnapshotis still preparing, without extending the metadata writertransaction.
Problem
createSnapshotcreates asnapshots/new-*directory before acquiring themetadata writer transaction.
A concurrent
Removeperforms a global orphan scan of the snapshots directory.Because the staging directory does not yet have a metadata ID, the scan can
classify it as an orphan and delete it. Snapshot creation then fails when it
tries to rename the missing staging directory:
This was observed downstream under concurrent image pulls and snapshot
removals.
Fix
Define a shared local prefix for snapshot staging directories and exclude
directories with that prefix from
getCleanupDirectories.Successful snapshot creation renames the staging directory to its allocated
metadata ID. Normal preparation failures continue to remove it through the
existing deferred cleanup.
A staging directory left by a daemon crash can be handled separately by a
future
Cleanupimplementation.