Skip to content

Commit

Permalink
gh-18 prevent data race in extension looker upper through lock
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennedi committed Dec 3, 2019
1 parent de4e50d commit a295c8d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions extensions/looker_upper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func NewLookerUpper(repo RetrieverRepo) *LookerUpper {
}

func (lu *LookerUpper) Lookup(concept string) (*Extension, error) {
lu.Lock()
defer lu.Unlock()

ext, ok := lu.db[concept]
if !ok {
return nil, nil
Expand All @@ -41,17 +44,16 @@ func (lu *LookerUpper) initWatcher() {

go func() {
for res := range updateCh {
// lu.Lock()
// defer lu.Unlock()

lu.updateDB(res)
}
}()
}

func (lu *LookerUpper) updateDB(list []Extension) {
lu.Lock()
defer lu.Unlock()

for _, ext := range list {
lu.db[ext.Concept] = ext
}

}

0 comments on commit a295c8d

Please sign in to comment.