aboutsummaryrefslogtreecommitdiff
path: root/middleware
diff options
context:
space:
mode:
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)