internal: fix high cpu when backend isnt healthy

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-04-29 10:03:37 +02:00
parent 254249e38b
commit eb6cfd22a7
1 changed files with 13 additions and 7 deletions

View File

@ -83,14 +83,20 @@ func (g *GoUnicorn) healthcheck() {
// Default healthcheck is every 1 second on startup // Default healthcheck is every 1 second on startup
// once we've been healthy once, increase to 30 seconds // once we've been healthy once, increase to 30 seconds
for range time.Tick(time.Second) { func() {
if check() { for {
g.log.Info("backend is alive, backing off with healthchecks") select {
g.HealthyCallback() case <-time.Tick(1 * time.Second):
break 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) { for range time.Tick(30 * time.Second) {
check() check()
} }