Fix health race (#645)

* Revert "middleware/proxy: Make Unhealthy a pointer (#615)"

This reverts commit acbf522ceb.

* middleware/proxy: add proper locking

This add the proper locking around `Unhealthy`.
This commit is contained in:
Miek Gieben 2017-04-24 20:37:43 +01:00 committed by GitHub
parent bfa18470e5
commit 003b1bf678
6 changed files with 26 additions and 28 deletions

View file

@ -3,6 +3,7 @@ package proxy
import (
"errors"
"sync"
"sync/atomic"
"time"
@ -56,9 +57,10 @@ type UpstreamHost struct {
Name string // IP address (and port) of this upstream host
Fails int32
FailTimeout time.Duration
Unhealthy *bool
Unhealthy bool
CheckDown UpstreamHostDownFunc
WithoutPathPrefix string
checkMu sync.Mutex
}
// Down checks whether the upstream host is down or not.
@ -68,7 +70,7 @@ func (uh *UpstreamHost) Down() bool {
if uh.CheckDown == nil {
// Default settings
fails := atomic.LoadInt32(&uh.Fails)
return *uh.Unhealthy || fails > 0
return uh.Unhealthy || fails > 0
}
return uh.CheckDown(uh)
}