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 race condition in foundRefs.claim() #335

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions searcher/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type limiter chan bool
type foundRefs struct {
refs []*index.IndexRef
claimed map[*index.IndexRef]bool
lock sync.Mutex
}

func makeLimiter(n int) limiter {
Expand Down Expand Up @@ -85,6 +86,9 @@ func (r *foundRefs) find(url, rev string) *index.IndexRef {
* collected at the end of startup.
*/
func (r *foundRefs) claim(ref *index.IndexRef) {
r.lock.Lock()
defer r.lock.Unlock()

r.claimed[ref] = true
}

Expand All @@ -93,6 +97,9 @@ func (r *foundRefs) claim(ref *index.IndexRef) {
* found in the dbpath but were not claimed during startup.
*/
func (r *foundRefs) removeUnclaimed() error {
r.lock.Lock()
defer r.lock.Unlock()

for _, ref := range r.refs {
if r.claimed[ref] {
continue
Expand Down