From 62d532e2ce6c3c4896cc2003b4d71af331df48dc Mon Sep 17 00:00:00 2001 From: cclohmar Date: Fri, 7 Aug 2026 12:25:09 +0000 Subject: [PATCH] fix: health check treats 4xx as success (WAF reachable, just no index page) --- health.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/health.go b/health.go index 6f67793..a7621d3 100644 --- a/health.go +++ b/health.go @@ -18,19 +18,21 @@ func startHealthCheck() { } client := &http.Client{Timeout: 2 * time.Second} - resp, err := client.Head(cfg.WAFURL + "/") - if err != nil { - log.Printf("WAF health check FAILED: %v", err) + resp, err := client.Head(cfg.WAFURL + "/") + if err != nil { + log.Printf("WAF health check FAILED: %v", err) + breaker.RecordFailure() + } else { + resp.Body.Close() + // Any response (2xx, 3xx, 4xx) means WAF is reachable. + // Only 5xx or connection errors indicate the WAF is unhealthy. + if resp.StatusCode >= 500 { + log.Printf("WAF health check: status %d", resp.StatusCode) breaker.RecordFailure() } else { - resp.Body.Close() - if resp.StatusCode < 500 { - breaker.RecordSuccess() - } else { - log.Printf("WAF health check: status %d", resp.StatusCode) - breaker.RecordFailure() - } + breaker.RecordSuccess() } + } time.Sleep(interval) }