Skip to content

Commit a23fb83

Browse files
committed
assure conch is returned same time as the lock
1 parent 55fe3c9 commit a23fb83

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/router/router.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ func (r *Router) doSelection() {
9898
select {
9999
case _ = <-r.theConch:
100100
r.selectionInProgress.Lock()
101-
defer r.selectionInProgress.Unlock()
101+
defer func() {
102+
r.selectionInProgress.Unlock()
103+
if log.GetLevel() >= log.DebugLevel {
104+
log.Debugf("Returning selection lock")
105+
}
106+
r.theConch <- struct{}{}
107+
}()
108+
102109
if log.GetLevel() >= log.DebugLevel {
103110
log.Debugf("Got selection lock; performing selection")
104111
}
@@ -138,14 +145,11 @@ func (r *Router) doSelection() {
138145

139146
r.metrics.selectedBackends.Set(float64(len(result.Selection)))
140147
r.metrics.selectionEvents.Inc()
141-
if log.GetLevel() >= log.DebugLevel {
142-
log.Debugf("Returning selection lock")
143-
}
144-
r.theConch <- struct{}{}
148+
145149
default:
146150
log.Warnf("Selection is already in-progress; awaiting result")
147151
r.selectionInProgress.RLock()
148-
defer r.selectionInProgress.RUnlock()
152+
r.selectionInProgress.RUnlock()
149153
}
150154
}
151155

0 commit comments

Comments
 (0)