hold listener lock while waiting for goroutines to finish

This commit is contained in:
Alexander Zielenski 2022-08-29 12:34:35 -07:00
parent ee24648300
commit 7ce19b75a8
No known key found for this signature in database
GPG Key ID: 754BC11B447F7843

View File

@ -751,7 +751,6 @@ func (p *sharedProcessor) run(stopCh <-chan struct{}) {
}() }()
<-stopCh <-stopCh
func() {
p.listenersLock.Lock() p.listenersLock.Lock()
defer p.listenersLock.Unlock() defer p.listenersLock.Unlock()
for listener := range p.listeners { for listener := range p.listeners {
@ -762,10 +761,8 @@ func (p *sharedProcessor) run(stopCh <-chan struct{}) {
// (processorListener cannot be re-used) // (processorListener cannot be re-used)
p.listeners = nil p.listeners = nil
// Reset to false since there are nil listeners, also to block new listeners // Reset to false since no listeners are running
// that are added from being run now that the processor was stopped
p.listenersStarted = false p.listenersStarted = false
}()
p.wg.Wait() // Wait for all .pop() and .run() to stop p.wg.Wait() // Wait for all .pop() and .run() to stop
} }
@ -789,7 +786,6 @@ func (p *sharedProcessor) shouldResync() bool {
listener.determineNextResync(now) listener.determineNextResync(now)
} }
} }
return resyncNeeded return resyncNeeded
} }