Kotlin / dokka

API documentation engine for Kotlin
https://kotl.in/dokka
Apache License 2.0
3.4k stars 399 forks source link

dokkaJavadocJar fires "java.lang.OutOfMemoryError: Metaspace" #1405

Closed elect86 closed 1 year ago

elect86 commented 4 years ago

Question

I added the following in my build.gradle.kts

val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
    dependsOn(tasks.dokkaJavadoc)
    from(tasks.dokkaJavadoc.get().outputDirectory.get())
    archiveClassifier.set("javadoc")
}

val dokkaHtmlJar by tasks.register<Jar>("dokkaHtmlJar") {
    dependsOn(tasks.dokkaHtml)
    from(tasks.dokkaHtml.get().outputDirectory.get())
    archiveClassifier.set("html-doc")
}

val sourceJar = task("sourceJar", Jar::class) {
    dependsOn(tasks["classes"])
    archiveClassifier.set("sources")
    from(sourceSets.main.get().allSource)
}

artifacts {
    archives(dokkaJavadocJar)
    archives(dokkaHtmlJar)
    archives(sourceJar)
}

However dokkaJavadocJar produces the titled error:

java.lang.OutOfMemoryError: Metaspace

and the following

Task :compileJava FAILED

But I'm pretty sure is dokkaJavadocJar the error root because if I comment it out, it works flawless

In order to fix this, I added in gradle.properties

org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m

Installation

I wonder if this is "fine" or something nasty is happening in the background I shall be aware of

Ps: the very same problem happens also in other projects

IgnatBeresnev commented 2 years ago

@GlenKPeterson is gradle.properties.kts a thing? Shouldn't it be just plain gradle.properties?

## gradle.properties
org.gradle.jvmargs=-XX:MaxMetaspaceSize=2G

If you're not using samples, you should not experience any major leaks. If it's an open source project, I can have a look, but if it's closed source, there's little I can do.


Try increasing metaspace and have a look at the Metaspace Graph in VisualVM. You should see the saw-like pattern just like in the screenshot above. If it only goes up and never down, try pressing Perform GC button, it should stall for a few seconds and then drop down. If it doesn't happen, there might be a leak. Generally any info that you can gather would be useful, we'd like to get this fixed if it's a leak.

If you need help or have questions, feel free to reach out to me at ignat.beresnev@jetbrains.com or by messaging me in the Kotlin Community Slack (same name there)

GlenKPeterson commented 1 year ago

I was just clearing large files out of my drive and found more data for you. I still get this issue from time to time. After looking at this briefly, I wonder if I'm using too many links in my KotlinDocs? Or linking to the Java or Kotlin documentation on the web too often? I have a vague recollection of using a compile parameter to specify which version of the standard library documentation to link to, but don't remember if that's for this project or not.

Screenshot from 2023-01-04 18-03-36

Screenshot from 2023-01-04 18-08-10

aSemy commented 1 year ago

I am working on a replacement for the Dokka Gradle Plugin, https://github.com/adamko-dev/dokkatoo, which uses the Gradle Worker API to run Dokka in an isolated process.

I had hoped that running Dokka in an isolated daemon would help, especially as Gradle should re-use the daemon, but unfortunately it hasn't helped, and anecdotally OOM errors seem to be triggered more often for even the basic examples andintegration-test projects.

Here is an example failure: https://github.com/adamko-dev/dokkatoo/actions/runs/4211535460/jobs/7310041760

Since I have set up Dokka to run in a separate process it should be possible to analyze the process independently of other work. I will see if I can set this up, but if anyone would like to try, please check out the project and run the tests, and hints or tips would be appreciated!

IgnatBeresnev commented 1 year ago

We've fixed all known Metaspace leaks as of today, and added some tests to detect such problems in the future. Unfortunately, Dokka still requires a considerable amount of memory to document large projects.

If you are experiencing Metaspace-related issues when running Dokka:

If you you have suspicions that Dokka is leaking memory or the Metaspace size you've set goes beyound reasonable, please create a separate issue for your case. We would appreciate having a reproducer and as much information as possible to collect.

I'm closing this general issue so that we can concentrate on specific cases.