From 6f135e89d71381f56665c109f88af3dde34342a3 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 18 Dec 2017 13:30:07 +0100 Subject: [PATCH] Make daemon starting more tolerant to the failures - retry (cherry picked from commit 386cfec) --- .../daemon/client/KotlinCompilerClient.kt | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index c93e88f212c..2fa802240ea 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -116,8 +116,9 @@ object KotlinCompilerClient { } else { if (!isLastAttempt && autostart) { - startDaemon(compilerId, newJVMOptions, daemonOptions, reportingTargets) - reportingTargets.report(DaemonReportCategory.DEBUG, "new daemon started, trying to find it") + if (startDaemon(compilerId, newJVMOptions, daemonOptions, reportingTargets)) { + reportingTargets.report(DaemonReportCategory.DEBUG, "new daemon started, trying to find it") + } } null } @@ -361,7 +362,7 @@ object KotlinCompilerClient { } - private fun startDaemon(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets) { + private fun startDaemon(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets): Boolean { val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java") val serverHostname = System.getProperty(JAVA_RMI_SERVER_HOSTNAME) ?: error("$JAVA_RMI_SERVER_HOSTNAME is not set!") val platformSpecificOptions = listOf( @@ -420,14 +421,22 @@ object KotlinCompilerClient { } ?: DAEMON_DEFAULT_STARTUP_TIMEOUT_MS if (daemonOptions.runFilesPath.isNotEmpty()) { val succeeded = isEchoRead.tryAcquire(daemonStartupTimeout, TimeUnit.MILLISECONDS) - if (!isProcessAlive(daemon)) - throw RuntimeException("Daemon terminated unexpectedly with error code: ${daemon.exitValue()}") - if (!succeeded) - throw RuntimeException("Unable to get response from daemon in $daemonStartupTimeout ms") + return when { + !isProcessAlive(daemon) -> { + reportingTargets.report(DaemonReportCategory.INFO, "Daemon terminated unexpectedly with error code: ${daemon.exitValue()}") + false + } + !succeeded -> { + reportingTargets.report(DaemonReportCategory.INFO, "Unable to get response from daemon in $daemonStartupTimeout ms") + false + } + else -> true + } } else // without startEcho defined waiting for max timeout Thread.sleep(daemonStartupTimeout) + return true } finally { // assuming that all important output is already done, the rest should be routed to the log by the daemon itself