aboutsummaryrefslogtreecommitdiff
path: root/middleware/proxy/proxy.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2017-04-24 20:37:43 +0100
committerGravatar GitHub <noreply@github.com> 2017-04-24 20:37:43 +0100
commit003b1bf678f6fc1d551fed5184adccde2137e86f (patch)
treef8d3af6f48ef9d73c841095cf3c04649b11a1fac /middleware/proxy/proxy.go
parentbfa18470e53c5058237e02b56c97c5d0a2cb47be (diff)
downloadcoredns-003b1bf678f6fc1d551fed5184adccde2137e86f.tar.gz
coredns-003b1bf678f6fc1d551fed5184adccde2137e86f.tar.zst
coredns-003b1bf678f6fc1d551fed5184adccde2137e86f.zip
Fix health race (#645)
* Revert "middleware/proxy: Make Unhealthy a pointer (#615)" This reverts commit acbf522cebdcd53c26d153c1d9267d709ba75f64. * middleware/proxy: add proper locking This add the proper locking around `Unhealthy`.
Diffstat (limited to 'middleware/proxy/proxy.go')
-rw-r--r--middleware/proxy/proxy.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/middleware/proxy/proxy.go b/middleware/proxy/proxy.go
index ca7b8daa0..ce8b99d83 100644
--- a/middleware/proxy/proxy.go
+++ b/middleware/proxy/proxy.go
@@ -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)
}