Skip to content

Commit

Permalink
fix race in foundRefs.claim() (hound-search#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
igorwwwwwwwwwwwwwwwwwwww authored and yelizariev committed May 4, 2020
1 parent 91e3b88 commit 9f24b0f
Showing 1 changed file with 7 additions and 0 deletions.
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

0 comments on commit 9f24b0f

Please sign in to comment.