Skip to content

Commit

Permalink
[common]: fix potential leak on Sleep.
Browse files Browse the repository at this point in the history
  • Loading branch information
shirou committed May 28, 2023
1 parent 03ae19b commit 3e789a4
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/common/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e789a4

Please sign in to comment.