mirror of
https://github.com/moby/buildkit.git
synced 2026-08-05 07:10:23 +00:00
don't commit cache mounts on error
Cache mount instances are shared between multiple vertextes/builds so if one of the cloned instance gets committed reference count will get corrupted as other parts of the code still see reference as mountable. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
@@ -127,6 +127,7 @@ type MountRef struct {
|
||||
type MountMutableRef struct {
|
||||
Ref cache.MutableRef
|
||||
MountIndex int
|
||||
NoCommit bool
|
||||
}
|
||||
|
||||
type MakeMutable func(m *opspb.Mount, ref cache.ImmutableRef) (cache.MutableRef, error)
|
||||
@@ -196,6 +197,7 @@ func PrepareMounts(ctx context.Context, mm *mounts.MountManager, cm cache.Manage
|
||||
p.Actives = append(p.Actives, MountMutableRef{
|
||||
MountIndex: i,
|
||||
Ref: active,
|
||||
NoCommit: true,
|
||||
})
|
||||
if m.Output != opspb.SkipOutput && ref != nil {
|
||||
p.OutputRefs = append(p.OutputRefs, MountRef{
|
||||
|
||||
@@ -243,12 +243,16 @@ func (e *execOp) Exec(ctx context.Context, g session.Group, inputs []solver.Resu
|
||||
execMounts[p.OutputRefs[i].MountIndex] = res
|
||||
}
|
||||
for _, active := range p.Actives {
|
||||
ref, cerr := active.Ref.Commit(ctx)
|
||||
if cerr != nil {
|
||||
err = errors.Wrapf(err, "error committing %s: %s", active.Ref.ID(), cerr)
|
||||
continue
|
||||
if active.NoCommit {
|
||||
active.Ref.Release(context.TODO())
|
||||
} else {
|
||||
ref, cerr := active.Ref.Commit(ctx)
|
||||
if cerr != nil {
|
||||
err = errors.Wrapf(err, "error committing %s: %s", active.Ref.ID(), cerr)
|
||||
continue
|
||||
}
|
||||
execMounts[active.MountIndex] = worker.NewWorkerRefResult(ref, e.w)
|
||||
}
|
||||
execMounts[active.MountIndex] = worker.NewWorkerRefResult(ref, e.w)
|
||||
}
|
||||
err = errdefs.WithExecError(err, execInputs, execMounts)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user