aboutsummaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
authorGravatar Michael S. Fischer <mfischer-zd@users.noreply.github.com> 2017-03-17 00:20:55 -0700
committerGravatar Miek Gieben <miek@miek.nl> 2017-03-17 07:20:55 +0000
commit7dc431ada3909aba9dfeaf64003718e0ea4d43b9 (patch)
tree04792744ba4202d44a0aa5fb8fa820805235ed56 /middleware
parentdfc71df07d7a19cc0227083ce6b04eea60ecd5a0 (diff)
downloadcoredns-7dc431ada3909aba9dfeaf64003718e0ea4d43b9.tar.gz
coredns-7dc431ada3909aba9dfeaf64003718e0ea4d43b9.tar.zst
coredns-7dc431ada3909aba9dfeaf64003718e0ea4d43b9.zip
middleware/proxy: fix race; add Go 1.7 backward compatibility (#603)
* Fix race on backend health status update * Ensure test case is compatible on Go 1.7
Diffstat (limited to 'middleware')
-rw-r--r--middleware/proxy/proxy.go2
-rw-r--r--middleware/proxy/upstream.go6
2 files changed, 7 insertions, 1 deletions
diff --git a/middleware/proxy/proxy.go b/middleware/proxy/proxy.go
index d21dee732..ce8b99d83 100644
--- a/middleware/proxy/proxy.go
+++ b/middleware/proxy/proxy.go
@@ -3,6 +3,7 @@ package proxy
import (
"errors"
+ "sync"
"sync/atomic"
"time"
@@ -59,6 +60,7 @@ type UpstreamHost struct {
Unhealthy bool
CheckDown UpstreamHostDownFunc
WithoutPathPrefix string
+ checkMu sync.Mutex
}
// Down checks whether the upstream host is down or not.
diff --git a/middleware/proxy/upstream.go b/middleware/proxy/upstream.go
index cabcd9ba8..c595976bc 100644
--- a/middleware/proxy/upstream.go
+++ b/middleware/proxy/upstream.go
@@ -250,7 +250,9 @@ func (u *staticUpstream) healthCheck() {
}
hostURL := "http://" + net.JoinHostPort(checkHostName, checkPort) + u.HealthCheck.Path
- host.Unhealthy = false
+
+ host.checkMu.Lock()
+ defer host.checkMu.Unlock()
if r, err := http.Get(hostURL); err == nil {
io.Copy(ioutil.Discard, r.Body)
@@ -259,6 +261,8 @@ func (u *staticUpstream) healthCheck() {
log.Printf("[WARNING] Health check URL %s returned HTTP code %d\n",
hostURL, r.StatusCode)
host.Unhealthy = true
+ } else {
+ host.Unhealthy = false
}
} else {
log.Printf("[WARNING] Health check probe failed: %v\n", err)