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 a360de2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ func (r *layerStore) Load() error {
}
}

info, statErr := os.Stat(r.layerspath())
if statErr != nil && !os.IsNotExist(statErr) {
return statErr
}

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

return err
}

Expand Down Expand Up @@ -1924,7 +1933,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 a360de2

Please sign in to comment.