Skip to content

Commit

Permalink
Remove context deadline checking in backOffContext (#113)
Browse files Browse the repository at this point in the history
* Remove ctx deadline check

* Add context error checking after stop
  • Loading branch information
swithek committed May 31, 2021
1 parent c2975ff commit a78d380
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 1 addition & 5 deletions context.go
Expand Up @@ -57,10 +57,6 @@ func (b *backOffContext) NextBackOff() time.Duration {
case <-b.ctx.Done():
return Stop
default:
return b.BackOff.NextBackOff()
}
next := b.BackOff.NextBackOff()
if deadline, ok := b.ctx.Deadline(); ok && deadline.Sub(time.Now()) < next { // nolint: gosimple
return Stop
}
return next
}
4 changes: 4 additions & 0 deletions retry.go
Expand Up @@ -62,6 +62,10 @@ func RetryNotifyWithTimer(operation Operation, b BackOff, notify Notify, t Timer
}

if next = b.NextBackOff(); next == Stop {
if cerr := ctx.Err(); cerr != nil {
return cerr
}

return err
}

Expand Down
2 changes: 1 addition & 1 deletion retry_test.go
Expand Up @@ -81,7 +81,7 @@ func TestRetryContext(t *testing.T) {
if err == nil {
t.Errorf("error is unexpectedly nil")
}
if err.Error() != "error (3)" {
if !errors.Is(err, context.Canceled) {
t.Errorf("unexpected error: %s", err.Error())
}
if i != cancelOn {
Expand Down

0 comments on commit a78d380

Please sign in to comment.