Skip to content

Commit

Permalink
assure conch is returned same time as the lock
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-deboer committed Aug 2, 2017
1 parent 55fe3c9 commit a23fb83
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ func (r *Router) doSelection() {
select {
case _ = <-r.theConch:
r.selectionInProgress.Lock()
defer r.selectionInProgress.Unlock()
defer func() {
r.selectionInProgress.Unlock()
if log.GetLevel() >= log.DebugLevel {
log.Debugf("Returning selection lock")
}
r.theConch <- struct{}{}
}()

if log.GetLevel() >= log.DebugLevel {
log.Debugf("Got selection lock; performing selection")
}
Expand Down Expand Up @@ -138,14 +145,11 @@ func (r *Router) doSelection() {

r.metrics.selectedBackends.Set(float64(len(result.Selection)))
r.metrics.selectionEvents.Inc()
if log.GetLevel() >= log.DebugLevel {
log.Debugf("Returning selection lock")
}
r.theConch <- struct{}{}

default:
log.Warnf("Selection is already in-progress; awaiting result")
r.selectionInProgress.RLock()
defer r.selectionInProgress.RUnlock()
r.selectionInProgress.RUnlock()
}
}

Expand Down

0 comments on commit a23fb83

Please sign in to comment.