Skip to content

Commit

Permalink
(*Store)Layer(): fix race when loading layers
Browse files Browse the repository at this point in the history
Make sure that the layer store is locked when loading the layers.

Reported-in: github.com/containers/podman/issues/11487
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
  • Loading branch information
vrothberg committed Sep 9, 2021
1 parent 79a3135 commit 6f10616
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3054,10 +3054,15 @@ func (s *store) Layers() ([]Layer, error) {
if err != nil {
return nil, err
}
if err := lstore.LoadLocked(); err != nil {
return nil, err
}
layers, err := lstore.Layers()

layers, err := func() ([]Layer, error) {
lstore.Lock()
defer lstore.Unlock()
if err := lstore.Load(); err != nil {
return nil, err
}
return lstore.Layers()
}()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6f10616

Please sign in to comment.