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
This commit is contained in:
Michael S. Fischer
2017-03-17 00:20:55 -07:00
committed by Miek Gieben
parent dfc71df07d
commit 7dc431ada3
3 changed files with 13 additions and 2 deletions

View File

@@ -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)