Skip to content

Commit

Permalink
Fix data race between ReloadIfChanged and read-only usage of layerStore
Browse files Browse the repository at this point in the history
There was a race condition if a goroutine accessed to layerStore public
methods under RO lock and at the same time ReloadIfChanged was called.
In real life, it can occurr when there are two concurrent PlayKube
requests in Podman.

Signed-off-by: Mikhail Khachayants <tyler92@inbox.ru>
  • Loading branch information
tyler92 committed Sep 5, 2022
1 parent 8aa3b3a commit aa6c22a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ func (r *layerStore) Load() error {
}
}

var info os.FileInfo
info, err = os.Stat(r.layerspath())

if info != nil {
r.layerspathModified = info.ModTime()
}

return err
}

Expand Down Expand Up @@ -1924,7 +1931,6 @@ func (r *layerStore) Modified() (bool, error) {
}
if info != nil {
tmodified = info.ModTime() != r.layerspathModified
r.layerspathModified = info.ModTime()
}

return tmodified, nil
Expand Down

0 comments on commit aa6c22a

Please sign in to comment.