Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: admin retry logic #2519

Merged
merged 2 commits into from
Jul 23, 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
4 changes: 2 additions & 2 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ func isErrNoController(err error) bool {
// provided retryable func) up to the maximum number of tries permitted by
// the admin client configuration
func (ca *clusterAdmin) retryOnError(retryable func(error) bool, fn func() error) error {
for attemptsRemaining := ca.conf.Admin.Retry.Max; ; {
for attemptsRemaining := ca.conf.Admin.Retry.Max + 1; ; {
err := fn()
attemptsRemaining--
if err == nil || attemptsRemaining == 0 || !retryable(err) {
if err == nil || attemptsRemaining <= 0 || !retryable(err) {
return err
}
Logger.Printf(
Expand Down
8 changes: 4 additions & 4 deletions admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1852,11 +1852,11 @@ func Test_retryOnError(t *testing.T) {
if err == nil {
t.Errorf("expected error but was nil")
}
if attempts != 3 {
t.Errorf("expected 3 attempts to have been made but was %d", attempts)
if attempts != 4 {
t.Errorf("expected 4 attempts to have been made but was %d", attempts)
}
if time.Since(startTime) >= 3*testBackoffTime {
t.Errorf("attempt+sleep+attempt+sleep+attempt should take less than 3 * backoff time")
if time.Since(startTime) >= 4*testBackoffTime {
t.Errorf("attempt+sleep+retry+sleep+retry+sleep+retry should take less than 4 * backoff time")
}
})
}