From 3e789a459a881bc31b8f24435fe02013818466ee Mon Sep 17 00:00:00 2001 From: shirou Date: Sun, 28 May 2023 12:32:10 +0000 Subject: [PATCH] [common]: fix potential leak on Sleep. --- internal/common/sleep.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/common/sleep.go b/internal/common/sleep.go index 8c35b17..9bed241 100644 --- a/internal/common/sleep.go +++ b/internal/common/sleep.go @@ -11,6 +11,9 @@ func Sleep(ctx context.Context, interval time.Duration) error { timer := time.NewTimer(interval) select { case <-ctx.Done(): + if !timer.Stop() { + <-timer.C + } return ctx.Err() case <-timer.C: return nil