Skip to content

Commit

Permalink
Merge pull request containers#1500 from fengxsong/quick_fix
Browse files Browse the repository at this point in the history
fix: add a local variable 'isRetryable' to avoid modifying the caller's Options
  • Loading branch information
openshift-merge-robot authored Jun 13, 2023
2 parents b73b520 + 48ddd77 commit 12cf968
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ func RetryIfNecessary(ctx context.Context, operation func() error, options *Opti

// IfNecessary retries the operation in exponential backoff with the retry Options.
func IfNecessary(ctx context.Context, operation func() error, options *Options) error {
if options.IsErrorRetryable == nil {
options.IsErrorRetryable = IsErrorRetryable
var isRetryable func(error) bool
if options.IsErrorRetryable != nil {
isRetryable = options.IsErrorRetryable
} else {
isRetryable = IsErrorRetryable
}
err := operation()
for attempt := 0; err != nil && options.IsErrorRetryable(err) && attempt < options.MaxRetry; attempt++ {
for attempt := 0; err != nil && isRetryable(err) && attempt < options.MaxRetry; attempt++ {
delay := time.Duration(int(math.Pow(2, float64(attempt)))) * time.Second
if options.Delay != 0 {
delay = options.Delay
Expand Down

0 comments on commit 12cf968

Please sign in to comment.