Improve default typed supervision backoff reset (#31222)

This commit is contained in:
Johan Andrén 2022-03-09 16:21:59 +01:00 committed by GitHub
parent bce426937d
commit 77727f0776
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 6 deletions

View file

@ -1009,6 +1009,11 @@ class SupervisionSpec extends ScalaTestWithActorTestKit("""
}
}
"default resetBackoffAfter to average of min and max backoff" in {
val strategy = SupervisorStrategy.restartWithBackoff(minBackoff = 100.millis, maxBackoff = 1.second, 0)
strategy.resetBackoffAfter should ===((100.millis + 1.second) / 2)
}
"restart with exponential backoff when deferred factory throws" in new FailingDeferredTestSetup(
failCount = 1,
strategy = SupervisorStrategy.restartWithBackoff(minBackoff = 100.millis.dilated, maxBackoff = 1.second, 0)) {

View file

@ -53,8 +53,9 @@ object SupervisorStrategy {
*
* During the back-off incoming messages are dropped.
*
* If no new exception occurs within the `minBackoff` duration the exponentially
* increased back-off timeout is reset.
* If no new exception occurs within `(minBackoff + maxBackoff) / 2` the exponentially
* increased back-off timeout is reset. This can be overridden by explicitly setting
* `resetBackoffAfter` using `withResetBackoffAfter` on the returned strategy.
*
* The strategy is applied also if the actor behavior is deferred and throws an exception during
* startup.
@ -72,7 +73,7 @@ object SupervisorStrategy {
minBackoff: FiniteDuration,
maxBackoff: FiniteDuration,
randomFactor: Double): BackoffSupervisorStrategy =
Backoff(minBackoff, maxBackoff, randomFactor, resetBackoffAfter = minBackoff)
Backoff(minBackoff, maxBackoff, randomFactor, resetBackoffAfter = (minBackoff + maxBackoff) / 2)
/**
* Java API: It supports exponential back-off between the given `minBackoff` and
@ -88,8 +89,9 @@ object SupervisorStrategy {
*
* During the back-off incoming messages are dropped.
*
* If no new exception occurs within the `minBackoff` duration the exponentially
* increased back-off timeout is reset.
* If no new exception occurs within `(minBackoff + maxBackoff) / 2` the exponentially
* increased back-off timeout is reset. This can be overridden by explicitly setting
* `resetBackoffAfter` using `withResetBackoffAfter` on the returned strategy.
*
* The strategy is applied also if the actor behavior is deferred and throws an exception during
* startup.
@ -303,7 +305,7 @@ sealed abstract class BackoffSupervisorStrategy extends SupervisorStrategy {
/**
* Scala API: The back-off algorithm is reset if the actor does not crash within the
* specified `resetBackoffAfter`. By default, the `resetBackoffAfter` has
* the same value as `minBackoff`.
* the value of `(minBackoff + maxBackoff) / 2`.
*/
def withResetBackoffAfter(timeout: FiniteDuration): BackoffSupervisorStrategy