Skip to content

Commit

Permalink
honor context deadlines, fix #53
Browse files Browse the repository at this point in the history
  • Loading branch information
cenkalti committed Sep 21, 2018
1 parent adb73d5 commit 047b249
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ func (b *backOffContext) Context() context.Context {

func (b *backOffContext) NextBackOff() time.Duration {
select {
case <-b.Context().Done():
case <-b.ctx.Done():
return Stop
default:
return b.BackOff.NextBackOff()
}
next := b.BackOff.NextBackOff()
if deadline, ok := b.ctx.Deadline(); ok && time.Until(deadline) < next {
return Stop
}
return next
}
2 changes: 1 addition & 1 deletion retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func RetryNotify(operation Operation, b BackOff, notify Notify) error {
return permanent.Err
}

if next = b.NextBackOff(); next == Stop {
if next = cb.NextBackOff(); next == Stop {
return err
}

Expand Down

0 comments on commit 047b249

Please sign in to comment.