He-Pin opened a new issue, #3238:
URL: https://github.com/apache/pekko/issues/3238
### Description
The `retry` pattern in `pekko.pattern` performs `maxAttempts + 1` total
attempts instead of `maxAttempts`.
### Affected code
`actor/src/main/scala/org/apache/pekko/pattern/RetrySupport.scala` (lines
382-396):
```scala
if (maxAttempts - attempted > 0) {
val result = tryAttempt()
// ... retry on failure ...
doRetry(attempted + 1)
} else {
tryAttempt() // one extra attempt when maxAttempts is exhausted
}
```
When `attempted == maxAttempts`, the condition `maxAttempts - attempted > 0`
is false, so the `else` branch executes `tryAttempt()` — one additional attempt
beyond the configured limit.
### Evidence
- The Scaladoc documents the parameter as `@param attempts the maximum
number of attempts` (lines 74, 159, 244, 326)
- The existing test suite (`RetrySpec.scala` lines 89-92, 107-114, 128-133)
codifies the off-by-one: `attempts = 5` produces 6 calls, `attempts = 999`
produces 1000 calls
- The `else { tryAttempt() }` branch is unconditionally executed after all
retries are exhausted
### Expected behavior
The total number of attempts should equal `maxAttempts`. When `maxAttempts`
is 5, exactly 5 attempts should be made.
### Suggested fix
Remove the `else { tryAttempt() }` branch, or adjust the condition to
`maxAttempts - attempted >= 0` and remove the else branch, ensuring the final
attempt happens inside the `if` block.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]