mirror of https://github.com/docker/docs.git
fix possible data race with failure count
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
34d4cae503
commit
69eabdc81f
|
@ -192,7 +192,7 @@ func (e *Engine) StartMonitorEvents() {
|
||||||
log.WithFields(log.Fields{"name": e.Name, "id": e.ID}).Errorf("Error monitoring events: %s.", err)
|
log.WithFields(log.Fields{"name": e.Name, "id": e.ID}).Errorf("Error monitoring events: %s.", err)
|
||||||
if !strings.Contains(err.Error(), "EOF") {
|
if !strings.Contains(err.Error(), "EOF") {
|
||||||
// failing node reconnect should use back-off strategy
|
// failing node reconnect should use back-off strategy
|
||||||
<-e.refreshDelayer.Wait(e.failureCount)
|
<-e.refreshDelayer.Wait(e.getFailureCount())
|
||||||
}
|
}
|
||||||
log.WithFields(log.Fields{"name": e.Name, "id": e.ID}).Errorf("Restart event monitoring.")
|
log.WithFields(log.Fields{"name": e.Name, "id": e.ID}).Errorf("Restart event monitoring.")
|
||||||
e.StartMonitorEvents()
|
e.StartMonitorEvents()
|
||||||
|
@ -366,6 +366,13 @@ func (e *Engine) incFailureCount() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getFailureCount returns a copy on the getFailureCount, thread-safe
|
||||||
|
func (e *Engine) getFailureCount() int {
|
||||||
|
e.RLock()
|
||||||
|
defer e.RUnlock()
|
||||||
|
return e.failureCount
|
||||||
|
}
|
||||||
|
|
||||||
// UpdatedAt returns the previous updatedAt time
|
// UpdatedAt returns the previous updatedAt time
|
||||||
func (e *Engine) UpdatedAt() time.Time {
|
func (e *Engine) UpdatedAt() time.Time {
|
||||||
e.RLock()
|
e.RLock()
|
||||||
|
@ -385,7 +392,7 @@ func (e *Engine) CheckConnectionErr(err error) {
|
||||||
e.setErrMsg("")
|
e.setErrMsg("")
|
||||||
// If current state is unhealthy, change it to healthy
|
// If current state is unhealthy, change it to healthy
|
||||||
if e.state == stateUnhealthy {
|
if e.state == stateUnhealthy {
|
||||||
log.WithFields(log.Fields{"name": e.Name, "id": e.ID}).Infof("Engine came back to life after %d retries. Hooray!", e.failureCount)
|
log.WithFields(log.Fields{"name": e.Name, "id": e.ID}).Infof("Engine came back to life after %d retries. Hooray!", e.getFailureCount())
|
||||||
e.emitEvent("engine_reconnect")
|
e.emitEvent("engine_reconnect")
|
||||||
e.setState(stateHealthy)
|
e.setState(stateHealthy)
|
||||||
}
|
}
|
||||||
|
@ -744,7 +751,7 @@ func (e *Engine) refreshLoop() {
|
||||||
|
|
||||||
// Engines keep failing should backoff
|
// Engines keep failing should backoff
|
||||||
// e.failureCount and e.opts.FailureRetry are type of int
|
// e.failureCount and e.opts.FailureRetry are type of int
|
||||||
backoffFactor := e.failureCount - e.opts.FailureRetry
|
backoffFactor := e.getFailureCount() - e.opts.FailureRetry
|
||||||
if backoffFactor < 0 {
|
if backoffFactor < 0 {
|
||||||
backoffFactor = 0
|
backoffFactor = 0
|
||||||
} else if backoffFactor > maxBackoffFactor {
|
} else if backoffFactor > maxBackoffFactor {
|
||||||
|
|
Loading…
Reference in New Issue