diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-08-07 18:02:24 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-08-07 18:02:24 -0600 |
commit | e2f913bb7f813ac2f79cd3644066eff3815accd4 (patch) | |
tree | 7576bd5463924d88637ec822e40dd94966fc1211 /modules/caddyhttp/reverseproxy/healthchecks.go | |
parent | 65a09524c3926547ed0b8515da211173df4fe379 (diff) |
reverseproxy: Minor fixes and cleanup
Now use context cancellation to stop active health checker, which is
simpler than and just as effective as using a separate stop channel.
Diffstat (limited to 'modules/caddyhttp/reverseproxy/healthchecks.go')
-rw-r--r-- | modules/caddyhttp/reverseproxy/healthchecks.go | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index ee56f33..79f18fc 100644 --- a/modules/caddyhttp/reverseproxy/healthchecks.go +++ b/modules/caddyhttp/reverseproxy/healthchecks.go @@ -78,7 +78,6 @@ type ActiveHealthChecks struct { // body of a healthy backend. ExpectBody string `json:"expect_body,omitempty"` - stopChan chan struct{} httpClient *http.Client bodyRegexp *regexp.Regexp logger *zap.Logger @@ -137,8 +136,7 @@ func (h *Handler) activeHealthChecker() { select { case <-ticker.C: h.doActiveHealthCheckForAllHosts() - case <-h.HealthChecks.Active.stopChan: - // TODO: consider using a Context for cancellation instead + case <-h.ctx.Done(): ticker.Stop() return } @@ -341,8 +339,8 @@ func (h *Handler) countFailure(upstream *Upstream) { if err != nil { h.HealthChecks.Passive.logger.Error("could not count failure", zap.String("host", upstream.Dial), - zap.Error(err), - ) + zap.Error(err)) + return } // forget it later @@ -357,8 +355,7 @@ func (h *Handler) countFailure(upstream *Upstream) { if err != nil { h.HealthChecks.Passive.logger.Error("could not forget failure", zap.String("host", upstream.Dial), - zap.Error(err), - ) + zap.Error(err)) } }(upstream.Host, failDuration) } |