Skip to content

Commit 3ba807b

Browse files
committed
fix: admin retry logic
The previous fix wasn't correct. While looking at the transaction_manager.go logic, it became clear that the intention is that retry.max should not count the first attempt. This seems very reasonable so this fixes the test and logic to reflect that. The original code would fail this updated test because it didn't make the final required attempt. Signed-off-by: Mark Hindess <[email protected]>
1 parent 08ff0ff commit 3ba807b

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

admin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func isErrNoController(err error) bool {
207207
// provided retryable func) up to the maximum number of tries permitted by
208208
// the admin client configuration
209209
func (ca *clusterAdmin) retryOnError(retryable func(error) bool, fn func() error) error {
210-
for attemptsRemaining := ca.conf.Admin.Retry.Max; ; {
210+
for attemptsRemaining := ca.conf.Admin.Retry.Max + 1; ; {
211211
err := fn()
212212
attemptsRemaining--
213213
if err == nil || attemptsRemaining == 0 || !retryable(err) {

admin_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1852,11 +1852,11 @@ func Test_retryOnError(t *testing.T) {
18521852
if err == nil {
18531853
t.Errorf("expected error but was nil")
18541854
}
1855-
if attempts != 3 {
1856-
t.Errorf("expected 3 attempts to have been made but was %d", attempts)
1855+
if attempts != 4 {
1856+
t.Errorf("expected 4 attempts to have been made but was %d", attempts)
18571857
}
1858-
if time.Since(startTime) >= 3*testBackoffTime {
1859-
t.Errorf("attempt+sleep+attempt+sleep+attempt should take less than 3 * backoff time")
1858+
if time.Since(startTime) >= 4*testBackoffTime {
1859+
t.Errorf("attempt+sleep+retry+sleep+retry+sleep+retry should take less than 4 * backoff time")
18601860
}
18611861
})
18621862
}

0 commit comments

Comments
 (0)