From cb400e3fac350c572761d72b8001301ddb835f27 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Fri, 24 Jan 2020 15:06:11 +0100 Subject: [PATCH] fix race in foundRefs.claim() --- searcher/searcher.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/searcher/searcher.go b/searcher/searcher.go index fbcd8048..67727b9d 100644 --- a/searcher/searcher.go +++ b/searcher/searcher.go @@ -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 { @@ -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 } @@ -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