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:
Aleh Reishal 2020-09-08 13:38:32 +03:00 committed by GitHub
parent 6e71accd90
commit e0ceb71ccd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,9 +12,7 @@ import scala.concurrent.duration.FiniteDuration
import scala.reflect.ClassTag
import scala.util.control.Exception.Catcher
import scala.util.control.NonFatal
import org.slf4j.event.Level
import akka.actor.DeadLetterSuppression
import akka.actor.Dropped
import akka.actor.typed.BehaviorInterceptor.PreStartTarget
@ -28,6 +26,8 @@ import akka.event.Logging
import akka.util.OptionVal
import akka.util.unused
import scala.util.Try
/**
* INTERNAL API
*/
@ -171,10 +171,8 @@ private object RestartSupervisor {
maxBackoff: FiniteDuration,
randomFactor: Double): FiniteDuration = {
val rnd = 1.0 + ThreadLocalRandom.current().nextDouble() * randomFactor
if (restartCount >= 30) // Duration overflow protection (> 100 years)
maxBackoff
else
maxBackoff.min(minBackoff * math.pow(2, restartCount)) * rnd match {
val calculatedDuration = Try(maxBackoff.min(minBackoff * math.pow(2, restartCount)) * rnd).getOrElse(maxBackoff)
calculatedDuration match {
case f: FiniteDuration => f
case _ => maxBackoff
}