Skip to content

Commit

Permalink
Merge pull request #1475 from shirou/feature/fix_potential_leak_on_co…
Browse files Browse the repository at this point in the history
…mmon_sleep

[common]: fix potential leak on Sleep.
  • Loading branch information
shirou authored May 29, 2023
2 parents 03ae19b + 3e789a4 commit 32e8a92
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 32e8a92

Please sign in to comment.