Skip to content

Commit

Permalink
Don't leak timer
Browse files Browse the repository at this point in the history
  • Loading branch information
sethvargo committed Feb 5, 2022
1 parent f691e5c commit 7a0bb9f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,19 @@ func Do(ctx context.Context, b Backoff, f RetryFunc) error {
return rerr.Unwrap()
}

// ctx.Done() has priority, so we test it alone first
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(next):
default:
}

t := time.NewTimer(next)
select {
case <-ctx.Done():
t.Stop()
return ctx.Err()
case <-t.C:
continue
}
}
Expand Down

0 comments on commit 7a0bb9f

Please sign in to comment.