Fix data race between ReloadIfChanged and read-only usage of layerStore

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>
This commit is contained in:
Mikhail Khachayants 2022-09-05 18:57:47 +03:00
parent 8aa3b3aef0
commit a360de27f3
No known key found for this signature in database
GPG Key ID: A4969FA4926D6611
1 changed files with 9 additions and 1 deletions

View File

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