From 9de2150069e4247fa8fab05c6d4ebbe69bb7a930 Mon Sep 17 00:00:00 2001 From: jiuker Date: Mon, 19 Aug 2024 20:07:13 +0800 Subject: [PATCH] fix: use time replace the ticker for heathcheck fix: use time replace the ticker for heathcheck --- main.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 0891498..3a8f430 100644 --- a/main.go +++ b/main.go @@ -313,17 +313,18 @@ func getHealthCheckURL(endpoint, healthCheckPath string, healthCheckPort int) (s // healthCheck - background routine which checks if a backend is up or down. func (b *Backend) healthCheck(ctxt context.Context) { - ticker := time.NewTicker(b.healthCheckDuration) - defer ticker.Stop() + timer := time.NewTimer(b.healthCheckDuration) + defer timer.Stop() for { select { case <-ctxt.Done(): return - case <-ticker.C: + case <-timer.C: err := b.doHealthCheck() if err != nil { console.Errorln(err) } + timer.Reset(b.healthCheckDuration) } } }