Repository navigation
Fix failed to commit on during finalize error - #6821
Merged
Merged
Conversation
When an ExecOp exec fails, ExecOp.Exec commits each output mutable
snapshot to an immutable ref, appends it to the results returned to the
solver, AND stores it (via the error-decoration defer) into the
ExecError. The error path stored the SAME *workerRefResult into
ExecError.Mounts that was already handed to the solver, so a single
committed output ref was owned through two independent channels but
backed by only one counted cache ref.
When the error owner is released (e.g. gateway/solver error cleanup),
that single release drains the shared refcount to zero, cascading into
equalMutable.release and deleting the mutable record's lease. The active
snapshot is protected only by that lease, so a subsequent containerd
metadata GC collects it. The surviving solver-side owner is then used as
the upper parent of a Diff, whose Finalize -> Snapshotter.Commit runs on
the already-collected active snapshot, producing:
failed to finalize upper parent during diff: failed to commit <active>
to <final> during finalize: failed to stat active key during commit:
snapshot <active> does not exist: not found
The fix is twofold:
- exec.go: clone the result (res.Clone()) before embedding it in
ExecError.Mounts so the error owner has its own counted ref.
- worker/result.go: make workerRefResult.Clone produce an independent
*WorkerRef (and thus an independent cache ref) instead of sharing the
embedded one and orphaning the original.
Both are required: the call-site clone is what stops the over-release,
and the Clone-method fix is what makes that clone actually independent
(otherwise it aliases the shared *WorkerRef and leaks the original ref).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
The layerParent and diffParents cases locked each parent's mutex and deferred the unlock to the end of the function, so the lock was held longer than the release it protects -- and in the diffParents case the lower parent's lock was still held while the upper parent was locked and released. Unlock each parent immediately after releasing it so the lock is held only for that parent's release, matching the mergeParents case in the same switch which already does this. This narrows the lock scope and avoids holding one parent's lock while acquiring another's. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Brian Goff <cpuguy83@gmail.com>
cpuguy83
previously approved these changes
Jun 2, 2026
Member
|
Oh except CI is failing. |
FileOpSolver.getInput wrapped each input cache.ImmutableRef in a fresh *workerRefResult without cloning, so ExecError.Inputs shared the same *immutableRef entry with the caller. A release on either side cascaded into equalMutable.release on a ref the other side still owned, surfacing as "snapshot does not exist" on a later Finalize -- same shape as the prior failed-exec output ref fix. Clone the ref so ExecError owns its own counted ref. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
tonistiigi
force-pushed
the
fix-failed-to-commit
branch
from
June 2, 2026 19:04
d5ec4ce to
b09b53e
Compare
cpuguy83
approved these changes
Jun 3, 2026
crazy-max
approved these changes
Jun 8, 2026
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.
replaces #6808
Updated fix. Changes:
Filenext toExec.I couldn't get a reasonable integration test but manual POC and analysis is in https://gist.github.com/tonistiigi/fb61083d56f8d70a952f9993a9334d8d that fails for both exec and file case before the patch is fixed by this.
Some other similar fixes in #6820
@cpuguy83