Merge pull request #22215 from akka/wip-after-throw-patriknw

handle IllegalStateException in CoordinatedShutdown
This commit is contained in:
Patrik Nordwall 2017-01-25 14:32:20 +01:00 committed by GitHub
commit cc57b34b01

View file

@ -307,18 +307,24 @@ final class CoordinatedShutdown private[akka] (
}).map(_ Done)(ExecutionContexts.sameThreadExecutionContext)
val timeout = phases(phase).timeout
val deadline = Deadline.now + timeout
val timeoutFut = after(timeout, system.scheduler) {
if (phase == CoordinatedShutdown.PhaseActorSystemTerminate && deadline.hasTimeLeft) {
// too early, i.e. triggered by system termination
val timeoutFut = try {
after(timeout, system.scheduler) {
if (phase == CoordinatedShutdown.PhaseActorSystemTerminate && deadline.hasTimeLeft) {
// too early, i.e. triggered by system termination
result
} else if (result.isCompleted)
Future.successful(Done)
else if (recoverEnabled) {
log.warning("Coordinated shutdown phase [{}] timed out after {}", phase, timeout)
Future.successful(Done)
} else
Future.failed(
new TimeoutException(s"Coordinated shutdown phase [$phase] timed out after $timeout"))
}
} catch {
case _: IllegalStateException
// The call to `after` threw IllegalStateException, triggered by system termination
result
} else if (result.isCompleted)
Future.successful(Done)
else if (recoverEnabled) {
log.warning("Coordinated shutdown phase [{}] timed out after {}", phase, timeout)
Future.successful(Done)
} else
Future.failed(
new TimeoutException(s"Coordinated shutdown phase [$phase] timed out after $timeout"))
}
Future.firstCompletedOf(List(result, timeoutFut))
})