Fix calculating backoff delay in order to prevent IllegalArgumentExce… (#29569)
* Fix calculating backoff delay in order to prevent IllegalArgumentException #29568 * Fix calculating backoff delay in order to prevent IllegalArgumentException #29568 / remove BackoffCalculatorSpec due to it is difficult to make calculateDelay testable and not tp break binary backward compatibility
This commit is contained in:
parent
6e71accd90
commit
e0ceb71ccd
1 changed files with 7 additions and 9 deletions
|
|
@ -12,9 +12,7 @@ import scala.concurrent.duration.FiniteDuration
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
import scala.util.control.Exception.Catcher
|
import scala.util.control.Exception.Catcher
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
|
|
||||||
import org.slf4j.event.Level
|
import org.slf4j.event.Level
|
||||||
|
|
||||||
import akka.actor.DeadLetterSuppression
|
import akka.actor.DeadLetterSuppression
|
||||||
import akka.actor.Dropped
|
import akka.actor.Dropped
|
||||||
import akka.actor.typed.BehaviorInterceptor.PreStartTarget
|
import akka.actor.typed.BehaviorInterceptor.PreStartTarget
|
||||||
|
|
@ -28,6 +26,8 @@ import akka.event.Logging
|
||||||
import akka.util.OptionVal
|
import akka.util.OptionVal
|
||||||
import akka.util.unused
|
import akka.util.unused
|
||||||
|
|
||||||
|
import scala.util.Try
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* INTERNAL API
|
* INTERNAL API
|
||||||
*/
|
*/
|
||||||
|
|
@ -171,13 +171,11 @@ private object RestartSupervisor {
|
||||||
maxBackoff: FiniteDuration,
|
maxBackoff: FiniteDuration,
|
||||||
randomFactor: Double): FiniteDuration = {
|
randomFactor: Double): FiniteDuration = {
|
||||||
val rnd = 1.0 + ThreadLocalRandom.current().nextDouble() * randomFactor
|
val rnd = 1.0 + ThreadLocalRandom.current().nextDouble() * randomFactor
|
||||||
if (restartCount >= 30) // Duration overflow protection (> 100 years)
|
val calculatedDuration = Try(maxBackoff.min(minBackoff * math.pow(2, restartCount)) * rnd).getOrElse(maxBackoff)
|
||||||
maxBackoff
|
calculatedDuration match {
|
||||||
else
|
case f: FiniteDuration => f
|
||||||
maxBackoff.min(minBackoff * math.pow(2, restartCount)) * rnd match {
|
case _ => maxBackoff
|
||||||
case f: FiniteDuration => f
|
}
|
||||||
case _ => maxBackoff
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class ScheduledRestart(owner: RestartSupervisor[_, _ <: Throwable]) extends DeadLetterSuppression
|
final case class ScheduledRestart(owner: RestartSupervisor[_, _ <: Throwable]) extends DeadLetterSuppression
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue