diff --git a/common/backoff/retry.go b/common/backoff/retry.go index b6f7b04eb82..06c943fb197 100644 --- a/common/backoff/retry.go +++ b/common/backoff/retry.go @@ -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() } @@ -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() } diff --git a/common/backoff/retry_test.go b/common/backoff/retry_test.go index aa78157cfa0..4b6f55d5ddf 100644 --- a/common/backoff/retry_test.go +++ b/common/backoff/retry_test.go @@ -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") } @@ -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,