Skip to content

Commit 6e732e7

Browse files
authored
Return last error instead of ctx error (#3857)
* return last err instead of ctx err * comments
1 parent 0e4506b commit 6e732e7

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

common/backoff/retry.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func RetryContext(
161161
t.Stop()
162162
}
163163
}
164+
// always return the last error we got from operation, even if it is not useful
165+
// this retry utility does not have enough information to do any filtering/mapping
166+
if err != nil {
167+
return err
168+
}
164169
return ctx.Err()
165170
}
166171

@@ -214,7 +219,11 @@ func ThrottleRetryContext(
214219
timer.Stop()
215220
}
216221
}
217-
222+
// always return the last error we got from operation, even if it is not useful
223+
// this retry utility does not have enough information to do any filtering/mapping
224+
if err != nil {
225+
return err
226+
}
218227
return ctx.Err()
219228
}
220229

common/backoff/retry_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (s *RetrySuite) TestRetryContextTimeout() {
205205
err := RetryContext(ctx, func(ctx context.Context) error { return &someError{} },
206206
NewExponentialRetryPolicy(1*time.Second), retryEverything)
207207
elapsed := time.Since(start)
208-
s.ErrorIs(err, context.DeadlineExceeded)
208+
s.ErrorIs(err, &someError{})
209209
s.GreaterOrEqual(elapsed, timeout,
210210
"Call to retry should take at least as long as the context timeout")
211211
}
@@ -260,7 +260,7 @@ func (s *RetrySuite) TestThrottleRetryContext() {
260260
start = SystemClock.Now()
261261
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
262262
err = ThrottleRetryContext(ctx, func(_ context.Context) error { return &serviceerror.ResourceExhausted{} }, policy, retryEverything)
263-
s.Equal(ctx.Err(), err)
263+
s.Equal(&serviceerror.ResourceExhausted{}, err)
264264
s.LessOrEqual(
265265
time.Since(start),
266266
throttleInitialInterval,

0 commit comments

Comments
 (0)