Skip to content

Commit

Permalink
fix: use timer replace the ticker for heathcheck (#116)
Browse files Browse the repository at this point in the history
Fixed a potential timeout call that caused multiple health checks
  • Loading branch information
jiuker authored Aug 19, 2024
1 parent 6524e71 commit 3d42a20
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 3d42a20

Please sign in to comment.