- SonarQube Gradle plugin 2.7 and 2.6.2, Gradle 5.1.1
- OutOfMemory error (Metaspace)
- Repro steps: from commit 36ebc853a07054518c6b88eb03e8b465483c401b of https://gitlab.ow2.org/asm/asm, change sonar plugin version to 2.7 in build.gradle, and do “gradle/gradlew clean build test jacocoTestCoverageVerification uploadArchives sonarqube -Dsonar.host.url=<…>” a few times. The build crashes with an OutOfMemoryError.
An analysis of the memory dump with the Eclipse Memory Analyzer Tool shows a leak suspect in SonarQubePlugin.actionBroadcastMap. This is indeed a static hashmap which, if it is never cleaned (I haven’t looked at the code), will grow up indefinitely. This leak occurs even if the SonarQube tasks are not executed. It disappears only if the Gradle plugin is not applied at all to the Gradle projects.
This static hashmap was introduced in https://github.com/SonarSource/sonar-scanner-gradle/commit/e5da4f342a63163170c310f815260d192d0e5dbb. It was not there in the 2.6.2 version and this version does not have memory leaks when the Sonar gradle tasks are not executed.
However, there seems to be another leak affecting the 2.6.2 version. If you use the above repro steps, without changing the version to 2.7, you also get an OutOfMemory error after some time. This time the Eclipse Memory Analyzer Tool shows two leak suspects in
One instance of “com.persistit.JournalManager” loaded by “org.sonarsource.scanner.api.internal.IsolatedClassloader @ 0xe456e318” occupies 16 846 320 (14,91%) bytes. The memory is accumulated in one instance of “byte” loaded by “<system class loader>” .
One instance of “com.persistit.JournalManager$JournalCopier” loaded by “org.sonarsource.scanner.api.internal.IsolatedClassloader @ 0xe456e318” occupies 16 781 384 (14,85%) bytes. The memory is accumulated in one instance of “byte” loaded by “<system class loader>” .