From c1da2e287d15b03f81f71962ca26063423ba319e Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Mon, 18 Dec 2017 12:34:11 +0100 Subject: [PATCH] Make daemon session retrieval more robust to the daemon failures Original commit: f83dc0a067ce51d38b0dc9fb9fc03be9317fc8f9 --- .../kotlin/compilerRunner/JpsKotlinCompilerRunner.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index a049f3c31b7..aea4e742fd8 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -56,7 +56,14 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner() { @Synchronized private fun getOrCreateDaemonConnection(newConnection: ()-> CompileServiceSession?): CompileServiceSession? { - if (_jpsCompileServiceSession == null) { + // TODO: consider adding state "ping" to the daemon interface + if (_jpsCompileServiceSession == null || _jpsCompileServiceSession!!.compileService.getDaemonOptions() !is CompileService.CallResult.Good) { + _jpsCompileServiceSession?. let { + try { + it.compileService.releaseCompileSession(it.sessionId) + } + catch (_: Throwable) {} + } _jpsCompileServiceSession = newConnection() }