Skip to content

Commit

Permalink
retry: return immediately after context errors
Browse files Browse the repository at this point in the history
Before, the error may have been handled in the `<-ctx.Done()` case in
the `select` for the backoff sleep, since `DeadlineExceeded` errors
return `true` for `Temporary()` and `Timeout()`.
  • Loading branch information
lippserd committed Apr 3, 2024
1 parent 74c077a commit c7f5ed9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ func WithBackoff(
settings.OnError(time.Since(start), attempt, err, prevErr)
}

isRetryable := retryable(err)
if errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled) {
if prevErr != nil {
err = errors.Wrap(prevErr, err.Error())
}

if prevErr != nil && (errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled)) {
err = prevErr
return
}

if !isRetryable {
if !retryable(err) {
err = errors.Wrap(err, "can't retry")

return
Expand Down

0 comments on commit c7f5ed9

Please sign in to comment.