Skip to content

Commit 3e71788

Browse files
committed
[wip] Fix retry policy attempts to match server behavior
1 parent 1fd8ba0 commit 3e71788

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

internal/internal_task_handlers.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,18 @@ func getRetryBackoffWithNowTime(p *RetryPolicy, attempt int32, errReason string,
10571057
return noRetryBackoff
10581058
}
10591059

1060-
if p.MaximumAttempts > 0 && attempt > p.MaximumAttempts-1 {
1060+
if p.MaximumAttempts > 0 && attempt >= p.MaximumAttempts-1 {
1061+
// >=max-1 matches server behavior, which treats all this somewhat oddly, but it has been consistent for a long time.
1062+
// basically:
1063+
// - attempts means *retry attempts*, as it's only relevant for retries
1064+
// - max attempts means *total executions*, counting the first and all retries
1065+
// so e.g. max=3 means 3 calls, with attempt counts 0, 1, 2.
1066+
//
1067+
// first==0 makes the backoff interval below convenient (no coefficient),
1068+
// otherwise this feels confusing and it contributes to RetryPolicy's ambiguities,
1069+
// as some things apply to the *policy* (expiration, attempts displayed) and some to all executions (max attempts).
1070+
//
1071+
// we may be able to change this with a completely new API, but for now it must not change for backwards compat.
10611072
return noRetryBackoff // max attempt reached
10621073
}
10631074

0 commit comments

Comments
 (0)