From e2f913bb7f813ac2f79cd3644066eff3815accd4 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 7 Aug 2020 18:02:24 -0600 Subject: 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. --- modules/caddyhttp/reverseproxy/healthchecks.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'modules/caddyhttp/reverseproxy/healthchecks.go') 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) } -- cgit v1.2.3