Skip to content

Commit 7a0bb9f

Browse files
committed
Don't leak timer
1 parent f691e5c commit 7a0bb9f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

retry.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,19 @@ func Do(ctx context.Context, b Backoff, f RetryFunc) error {
7373
return rerr.Unwrap()
7474
}
7575

76+
// ctx.Done() has priority, so we test it alone first
7677
select {
7778
case <-ctx.Done():
7879
return ctx.Err()
79-
case <-time.After(next):
80+
default:
81+
}
82+
83+
t := time.NewTimer(next)
84+
select {
85+
case <-ctx.Done():
86+
t.Stop()
87+
return ctx.Err()
88+
case <-t.C:
8089
continue
8190
}
8291
}

0 commit comments

Comments
 (0)