IDEA IllegalStateException: Service is dying when

2019-04-14 15:10发布

问题:

Yesterday I was working on my codebase and I was running my unit tests against my code when suddenly I saw this in the IDEA log:

Error:Kotlin: [Internal Error] java.lang.IllegalStateException: Service is dying at org.jetbrains.kotlin.daemon.common.CompileService$CallResult$Dying.get(CompileService.kt:60) at org.jetbrains.kotlin.daemon.common.CompileService$CallResult$Dying.get(CompileService.kt:59) at org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner.compileWithDaemon(JpsKotlinCompilerRunner.kt:127) at org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner.compileWithDaemonOrFallback(JpsKotlinCompilerRunner.kt:100) at org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner.compileWithDaemonOrFallback(JpsKotlinCompilerRunner.kt:35) at org.jetbrains.kotlin.compilerRunner.KotlinCompilerRunner.runCompiler(KotlinCompilerRunner.kt:115) at org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner.runK2JvmCompiler(JpsKotlinCompilerRunner.kt:65) at org.jetbrains.kotlin.jps.build.KotlinBuilder.compileToJvm(KotlinBuilder.kt:740) at org.jetbrains.kotlin.jps.build.KotlinBuilder.doCompileModuleChunk(KotlinBuilder.kt:458) at org.jetbrains.kotlin.jps.build.KotlinBuilder.doBuild(KotlinBuilder.kt:264) at org.jetbrains.kotlin.jps.build.KotlinBuilder.build(KotlinBuilder.kt:181) at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1282) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:956) at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1028) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:915) at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:741) at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:387) at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:195) at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:138) at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:295) at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:125) at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler$1.run(BuildMain.java:238) at org.jetbrains.jps.service.impl.SharedThreadPoolImpl$1.run(SharedThreadPoolImpl.java:44) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Was this an April's fool's joke from JetBrains?

I've never seen this before. killall java and an IDEA restart solved the problem and I was not able to reproduce this. Is this something which is documented (I did not found any hits on google) or just a one-off glitch in IDEA when compiling Kotlin code? What does this error mean?

Note that the unit test I ran was a simple exploratory test and I think it is irrelevant here:

internal fun fetchAsListWithSiblings(): List<Message<T>> {
    val first = this
    var currentMsg = first
    val result = mutableListOf(currentMsg)
    while(currentMsg.next.isPresent) {
        val next = currentMsg.next.get()
        currentMsg = next
        result.add(next)
    }
    return result
}


@Test
fun shouldFetchSiblingsWhenFetchSiblingsIsCalledWithMultipleSiblings() {
    val expected = listOf("foo", "bar", "baz")
    val messages = Message.createMultiple(expected)

    assertThat(messages.fetchAsListWithSiblings().map { it.payload }).isEqualTo(expected)
}

回答1:

It is the known problem - race condition on the parallel compilation start. Usually repeating the build solves it. Here is the relevant issue KT-15562 in the YouTrack. The problem is supposed to be finally fixed in Kotlin 1.1.2 release.