Implement graceful connection failure behavior on daemon connect and cancellation check

Should fix (or actually - behave gracefully on) #EA-74003, #EA-74493, #EA-76032, #EA-76529, #EA-81295
Tests added
This commit is contained in:
Ilya Chernikov
2016-04-26 08:53:30 +02:00
parent 336226ac9e
commit 1614aca48e
3 changed files with 146 additions and 2 deletions
@@ -23,12 +23,23 @@ import org.jetbrains.kotlin.daemon.common.Profiler
import org.jetbrains.kotlin.daemon.common.RmiFriendlyCompilationCancelledException
import org.jetbrains.kotlin.progress.CompilationCanceledException
import java.util.concurrent.TimeUnit
import java.util.logging.Logger
val CANCELED_STATUS_CHECK_THRESHOLD_NS = TimeUnit.MILLISECONDS.toNanos(100)
class RemoteCompilationCanceledStatusClient(val facade: CompilerCallbackServicesFacade, val profiler: Profiler = DummyProfiler()): CompilationCanceledStatus {
private val log by lazy { Logger.getLogger("compiler") }
@Volatile var lastChecked: Long = System.nanoTime()
override fun checkCanceled() {
fun cancelOnError(e: Exception) {
log.warning("error communicating with host, assuming compilation cancelled (${e.message})")
throw CompilationCanceledException()
}
val curNanos = System.nanoTime()
if (curNanos - lastChecked > CANCELED_STATUS_CHECK_THRESHOLD_NS) {
profiler.withMeasure(this) {
@@ -38,6 +49,19 @@ class RemoteCompilationCanceledStatusClient(val facade: CompilerCallbackServices
catch (e: RmiFriendlyCompilationCancelledException) {
throw CompilationCanceledException()
}
catch (e: java.rmi.ConnectIOException) {
cancelOnError(e)
}
catch (e: java.rmi.ConnectException) {
cancelOnError(e)
}
catch (e: java.rmi.NoSuchObjectException) {
// this was added mostly for tests since others are more difficult to emulate
cancelOnError(e)
}
catch (e: java.rmi.UnmarshalException) {
cancelOnError(e)
}
}
lastChecked = curNanos
}