Skip to content

Commit f97946c

Browse files
committed
builder-next: fix missing lock in ensurelayer
Signed-off-by: Tõnis Tiigi <[email protected]>
1 parent 6c10086 commit f97946c

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

builder/builder-next/adapters/snapshot/layer.go

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ func (s *snapshotter) GetDiffIDs(ctx context.Context, key string) ([]layer.DiffI
2222
}
2323

2424
func (s *snapshotter) EnsureLayer(ctx context.Context, key string) ([]layer.DiffID, error) {
25+
s.layerCreateLocker.Lock(key)
26+
defer s.layerCreateLocker.Unlock(key)
27+
2528
diffIDs, err := s.GetDiffIDs(ctx, key)
2629
if err != nil {
2730
return nil, err

builder/builder-next/adapters/snapshot/snapshot.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/moby/buildkit/identity"
1818
"github.com/moby/buildkit/snapshot"
1919
"github.com/moby/buildkit/util/leaseutil"
20+
"github.com/moby/locker"
2021
"github.com/opencontainers/go-digest"
2122
"github.com/pkg/errors"
2223
bolt "go.etcd.io/bbolt"
@@ -51,10 +52,11 @@ type checksumCalculator interface {
5152
type snapshotter struct {
5253
opt Opt
5354

54-
refs map[string]layer.Layer
55-
db *bolt.DB
56-
mu sync.Mutex
57-
reg graphIDRegistrar
55+
refs map[string]layer.Layer
56+
db *bolt.DB
57+
mu sync.Mutex
58+
reg graphIDRegistrar
59+
layerCreateLocker *locker.Locker
5860
}
5961

6062
// NewSnapshotter creates a new snapshotter
@@ -71,10 +73,11 @@ func NewSnapshotter(opt Opt, prevLM leases.Manager, ns string) (snapshot.Snapsho
7173
}
7274

7375
s := &snapshotter{
74-
opt: opt,
75-
db: db,
76-
refs: map[string]layer.Layer{},
77-
reg: reg,
76+
opt: opt,
77+
db: db,
78+
refs: map[string]layer.Layer{},
79+
reg: reg,
80+
layerCreateLocker: locker.New(),
7881
}
7982

8083
slm := newLeaseManager(s, prevLM)

0 commit comments

Comments
 (0)