Skip to content

Commit 0835d1a

Browse files
committed
fix bug that overwrites last error when context is canceled
1 parent f0085d2 commit 0835d1a

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

retry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func Do(retryableFunc RetryableFunc, opts ...Option) error {
155155
if config.lastErrorOnly {
156156
return config.context.Err()
157157
}
158+
n++
158159
errorLog[n] = config.context.Err()
159160
return errorLog
160161
}

retry_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ func TestContext(t *testing.T) {
364364

365365
expectedErrorFormat := `All attempts fail:
366366
#1: test
367-
#2: context canceled`
367+
#2: test
368+
#3: context canceled`
368369
assert.Equal(t, expectedErrorFormat, err.Error(), "retry error format")
369370
assert.Equal(t, 2, retrySum, "called at most once")
370371
})

0 commit comments

Comments
 (0)