Skip to content

Commit

Permalink
Capture throwable inside generateDocumentation thread (#2935)
Browse files Browse the repository at this point in the history
Fixes #2934
  • Loading branch information
jush committed Apr 17, 2023
1 parent 5e81202 commit 115a318
Showing 1 changed file with 4 additions and 0 deletions.
Expand Up @@ -20,6 +20,7 @@ import org.gradle.work.DisableCachingByDefault
import org.jetbrains.dokka.*
import org.jetbrains.dokka.plugability.ConfigurableBlock
import org.jetbrains.dokka.plugability.DokkaPlugin
import java.util.concurrent.atomic.AtomicReference
import java.util.function.BiConsumer
import kotlin.reflect.full.createInstance

Expand Down Expand Up @@ -203,14 +204,17 @@ abstract class AbstractDokkaTask : DefaultTask() {
internal open fun generateDocumentation() {
DokkaBootstrap(runtime, DokkaBootstrapImpl::class).apply {
configure(buildDokkaConfiguration().toCompactJsonString(), createProxyLogger())
val uncaughtExceptionHolder = AtomicReference<Throwable?>()
/**
* Run in a new thread to avoid memory leaks that are related to ThreadLocal (that keeps `URLCLassLoader`)
* Currently, all `ThreadLocal`s leaking are in the compiler/IDE codebase.
*/
Thread { generate() }.apply {
setUncaughtExceptionHandler { _, throwable -> uncaughtExceptionHolder.set(throwable) }
start()
join()
}
uncaughtExceptionHolder.get()?.let { throw it }
}
}

Expand Down

0 comments on commit 115a318

Please sign in to comment.