From eb6cfd22a72970dfdab0314d4f1bd3038d3b88c7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 29 Apr 2022 10:03:37 +0200 Subject: [PATCH] internal: fix high cpu when backend isnt healthy Signed-off-by: Jens Langhammer --- internal/gounicorn/gounicorn.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/internal/gounicorn/gounicorn.go b/internal/gounicorn/gounicorn.go index f41f219b3..a63cc43ac 100644 --- a/internal/gounicorn/gounicorn.go +++ b/internal/gounicorn/gounicorn.go @@ -83,14 +83,20 @@ func (g *GoUnicorn) healthcheck() { // Default healthcheck is every 1 second on startup // once we've been healthy once, increase to 30 seconds - for range time.Tick(time.Second) { - if check() { - g.log.Info("backend is alive, backing off with healthchecks") - g.HealthyCallback() - break + func() { + for { + select { + case <-time.Tick(1 * time.Second): + if check() { + g.log.Info("backend is alive, backing off with healthchecks") + g.HealthyCallback() + return + } else { + g.log.Debug("backend not alive yet") + } + } } - g.log.Debug("backend not alive yet") - } + }() for range time.Tick(30 * time.Second) { check() }