-
Notifications
You must be signed in to change notification settings - Fork 249
[narInfoCache] Use sync.Map and simplify IsInBinaryCache #1473
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0bc1dd6
[narInfoCache] Simplify IsInBinaryCache
mikeland73 f2542f9
Fix
mikeland73 252ffb6
Fix2
mikeland73 f9b3cca
Use sync.Map
mikeland73 7cada0b
Simplify more
mikeland73 7e527a4
Remove comment
mikeland73 4fc377e
Reduce race condition
mikeland73 e042a78
Fix race
mikeland73 c747352
Use once
mikeland73 fc483da
Bump go version
mikeland73 67d0f5b
comments
mikeland73 ad45762
simplify code
mikeland73 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gcurtis @savil using defer here is functionally identical to what was previously handled in line 119 except now it is handled 100% of the time.
This in conjunction with
LoadOrStore
in line 125 guarantee that the first result is preserved forever (so a race condition cannot replace an existing value). This fixes an existing race condition where two calls tofillNarInfoCacheIfNeeded
could override each other if they had different results.This fix also removes the race condition where an early
false
causes another goroutine to returnfalse
early.It partially* fixes multiple goroutines trying to fetch the same result at the same time. In that case only the first result is saved and other goroutines return the same result. Previously, each call to
fillNarInfoCacheIfNeeded
could return a different result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand this scenario. Care to elaborate?
Did you try @gcurtis 's suggestion of using
sync.Once
s? I think that would address this.