Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return last error instead of ctx error #3857

Merged
merged 3 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common/backoff/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ func RetryContext(
t.Stop()
}
}
// always return the last error we got from operation, even if it is not useful
// this retry utility does not have enough information to do any filtering/mapping
if err != nil {
return err
}
return ctx.Err()
}

Expand Down Expand Up @@ -214,7 +219,11 @@ func ThrottleRetryContext(
timer.Stop()
}
}

// always return the last error we got from operation, even if it is not useful
// this retry utility does not have enough information to do any filtering/mapping
if err != nil {
return err
}
return ctx.Err()
}

Expand Down
4 changes: 2 additions & 2 deletions common/backoff/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (s *RetrySuite) TestRetryContextTimeout() {
err := RetryContext(ctx, func(ctx context.Context) error { return &someError{} },
NewExponentialRetryPolicy(1*time.Second), retryEverything)
elapsed := time.Since(start)
s.ErrorIs(err, context.DeadlineExceeded)
s.ErrorIs(err, &someError{})
s.GreaterOrEqual(elapsed, timeout,
"Call to retry should take at least as long as the context timeout")
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (s *RetrySuite) TestThrottleRetryContext() {
start = SystemClock.Now()
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
err = ThrottleRetryContext(ctx, func(_ context.Context) error { return &serviceerror.ResourceExhausted{} }, policy, retryEverything)
s.Equal(ctx.Err(), err)
s.Equal(&serviceerror.ResourceExhausted{}, err)
s.LessOrEqual(
time.Since(start),
throttleInitialInterval,
Expand Down