Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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())
mtrmac marked this conversation as resolved.
Show resolved Hide resolved
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 {
mtrmac marked this conversation as resolved.
Show resolved Hide resolved
tmodified = info.ModTime() != r.layerspathModified
r.layerspathModified = info.ModTime()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the state of an object in a constant (by meaning) function is a bit strange. From my point of view, such functions should repeatedly return the same value. This was not the case before the fix.

}

return tmodified, nil
Expand Down