Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture throwable inside generateDocumentation thread #2935

Merged
merged 2 commits into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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