Attempt to grab read statelock in emit metrics to remove some raciness (#6829)

This commit is contained in:
Jeff Mitchell 2019-06-05 12:26:29 -04:00 committed by GitHub
parent f5baee5b55
commit b4cc1413f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1663,6 +1663,11 @@ func (c *Core) emitMetrics(stopCh chan struct{}) {
c.metricsMutex.Unlock()
case <-writeTimer:
if stopped := grabLockOrStop(c.stateLock.RLock, c.stateLock.RUnlock, stopCh); stopped {
// Go through the loop again, this time the stop channel case
// should trigger
continue
}
if c.perfStandby {
syncCounter(c)
} else {
@ -1671,6 +1676,7 @@ func (c *Core) emitMetrics(stopCh chan struct{}) {
c.logger.Error("writing request counters to barrier", "err", err)
}
}
c.stateLock.RUnlock()
case <-stopCh:
return