(*Store)Layer(): fix race when loading layers

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>
This commit is contained in:
Valentin Rothberg 2021-09-09 16:25:23 +02:00
parent 79a3135536
commit 6f106160e7
1 changed files with 9 additions and 4 deletions

View File

@ -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
}