Skip to content

Commit

Permalink
Improved memory consumption on timeout checks (#90)
Browse files Browse the repository at this point in the history
Thank you for the contribution! 💚
  • Loading branch information
dnozdrin authored Mar 14, 2023
1 parent ef872fc commit 19b67d6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion health.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ func (h *Health) Measure(ctx context.Context) Check {
defer close(resCh)
}()

timeout := time.NewTimer(c.Timeout)

select {
case <-time.After(c.Timeout):
case <-timeout.C:
mu.Lock()
defer mu.Unlock()

Expand All @@ -210,6 +212,10 @@ func (h *Health) Measure(ctx context.Context) Check {
failures[c.Name] = string(StatusTimeout)
status = getAvailability(status, c.SkipOnErr)
case res := <-resCh:
if !timeout.Stop() {
<-timeout.C
}

mu.Lock()
defer mu.Unlock()

Expand Down

0 comments on commit 19b67d6

Please sign in to comment.