Exception in thread "Daemon client event forwarder" java.lang.OutOfMemoryError: Java heap space

  • Sonarqube enterprise version 9.5.0, sonar scanner version is 4.3.0.2102
  • Trying to upgrade from 9.3.0 to 9.5.0
  • Running sonar scan from jenkins pipeline
  • Running sonar scan using sonar gradle
  • The project has build.gradle file with below dependecies and task.
    dependencies {
        classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"
    }

sonarqube { 	
	properties { 		
		property "sonar.jacoco.reportPaths", "${buildDir}/jacoco/test.xml"
		property "sonar.groovy.jacoco.reportPath", "${buildDir}/jacoco/test.xml"
	} 
}
  • For one of the java based project, the sonarqube task is getting failed with error message.
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Exception in thread "Daemon client event forwarder" java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.addConditionWaiter(AbstractQueuedSynchronizer.java:1896)
	at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2114)
	at java.base/java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:458)
	at org.gradle.launcher.daemon.server.exec.DaemonConnectionBackedEventConsumer$ForwardEvents.getNextEvent(DaemonConnectionBackedEventConsumer.java:72)
	at org.gradle.launcher.daemon.server.exec.DaemonConnectionBackedEventConsumer$ForwardEvents.run(DaemonConnectionBackedEventConsumer.java:59)
Exception in thread "Memory manager" java.lang.OutOfMemoryError: Java heap space
Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonarqube'.
> Java heap space

Based upon searching, i added gradle.properties file with below section to the project folder and the job/scan passed successfully.
org.gradle.jvmargs=-XX:PermSize=256M -XX:MaxPermSize=1024M

Just to make sure I downgraded the sonarqube back to 9.3.0 and the same job/scan passed.
It seems the newer version require specific heap size set for scans.
Is it expected. ??
is there solution apart from adding gradle.properties file.

Hey there.

It would probably be useful to start by adding --info to your grade command so we can see where in the scan it runs out of memory.

Hi Colin,
Please find the below log with --info added to scan.

> Task :sonarqube
Caching disabled for task ':sonarqube' because:
  Build cache is disabled
Task ':sonarqube' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
User cache: /home/jenkins/.sonar/cache
Default locale: "en_US", source code encoding: "UTF-8"
Load global settings
Load global settings (done) | time=251ms
Server id: xxxxxxxxxxxxxxxxxxxxx
User cache: /home/jenkins/.sonar/cache
Load/download plugins
Load plugins index
Load plugins index (done) | time=54ms
Load/download plugins (done) | time=2407ms
Loaded core extensions: developer-scanner
Process project properties
Process project properties (done) | time=12ms
Execute project builders
Execute project builders (done) | time=1ms
Project key: <project_key>
Base dir: /home/jenkins/workspace/_sonarqube-java-heap-space-issue
Working dir: /home/jenkins/workspace/_sonarqube-java-heap-space-issue/build/sonar
Load project settings for component key: '<project_key>'
Load project settings for component key: '<project_key>' (done) | time=41ms
Load project branches
Load project branches (done) | time=45ms
Load project pull requests
Load project pull requests (done) | time=34ms
Load branch configuration
Found manual configuration of branch/PR analysis. Skipping automatic configuration.
Load branch configuration (done) | time=1ms
Auto-configuring with CI 'Jenkins'
Load quality profiles
Load quality profiles (done) | time=104ms
Load active rules
Load active rules (done) | time=1469ms
Load analysis cache
Load analysis cache | time=24ms
Branch name: <branch name> 
Load project repositories
Load project repositories (done) | time=235ms
Indexing files...
Project configuration:

1239 files indexed

> Task :sonarqube
2 files ignored because of scm ignore settings
Quality profile for java: Sonar way without java10 local var code-smell issue
Quality profile for json: Sonar way
Quality profile for web: Sonar way
Quality profile for xml: Sonar way
Quality profile for yaml: Sonar way
------------- Run sensors on module <project_key>
Load metrics repository
Load metrics repository (done) | time=22ms
Sensor JavaSensor [java]
Configured Java source version (sonar.java.source): 11
JavaClasspath initialization
JavaClasspath initialization (done) | time=17ms
JavaTestClasspath initialization
JavaTestClasspath initialization (done) | time=21ms
The Java analyzer cannot skip unchanged files in this context. A full analysis is performed for all files.
Server-side caching is enabled. The Java analyzer was able to leverage cached data from previous analyses for 0 out of 1191 files. These files will not be parsed.
Using ECJ batch to parse 1051 Main java source files with batch size 26 KB.
Starting batch processing.

83% analyzed
Expiring Daemon because JVM heap space is exhausted
Daemon will be stopped at the end of the build after running out of JVM memory
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
100% analyzed
Batch processing: Done.
Did not optimize analysis for any files, performed a full analysis for all 1051 files.
Unresolved imports/types have been detected during analysis. Enable DEBUG mode to see them.
Use of preview features have been detected during analysis. Enable DEBUG mode to see them.
Using ECJ batch to parse 140 Test java source files with batch size 26 KB.
Starting batch processing.

Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted
Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
100% analyzed
Batch processing: Done.
Did not optimize analysis for any files, performed a full analysis for all 140 files.
No "Generated" source files to scan.
Sensor JavaSensor [java] (done) | time=182888ms
Sensor IaC CloudFormation Sensor [iac]

0 source files to be analyzed
0/0 source files have been analyzed
11 source files to be analyzed
11/11 source files have been analyzed
1212 source files to be analyzed
1212/1212 source files have been analyzed

> Task :sonarqube
Sensor IaC CloudFormation Sensor [iac] (done) | time=63ms
Sensor C# Project Type Information [csharp]
Sensor C# Project Type Information [csharp] (done) | time=3ms
Sensor C# Analysis Log [csharp]
Sensor C# Analysis Log [csharp] (done) | time=21ms
Sensor C# Properties [csharp]
Sensor C# Properties [csharp] (done) | time=0ms
Sensor SurefireSensor [java]
parsing [/home/jenkins/workspace/_sonarqube-java-heap-space-issue/build/test-results/test]
Sensor SurefireSensor [java] (done) | time=419ms
Sensor Removed properties sensor [java]
Sensor Removed properties sensor [java] (done) | time=1ms
Sensor HTML [web]
Sensor HTML [web] (done) | time=97ms
Sensor XML Sensor [xml]
Sensor XML Sensor [xml] (done) | time=704ms
Sensor Text Sensor [text]
Sensor Text Sensor [text] (done) | time=573ms
Sensor VB.NET Project Type Information [vbnet]
Sensor VB.NET Project Type Information [vbnet] (done) | time=2ms
Sensor VB.NET Analysis Log [vbnet]
Sensor VB.NET Analysis Log [vbnet] (done) | time=20ms
Sensor VB.NET Properties [vbnet]
Sensor VB.NET Properties [vbnet] (done) | time=0ms
Sensor JaCoCo XML Report Importer [jacoco]
Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
Sensor JaCoCo XML Report Importer [jacoco] (done) | time=492ms
Sensor CSS Rules [javascript]
Deploying custom rules bundle jar:file:/home/jenkins/.sonar/cache/06b160cbad8e9f8df7328b1a2c5a0afe/sonar-securityjsfrontend-plugin.jar!/js-vulnerabilities-rules-1.0.0.tgz to /home/jenkins/workspace/_sonarqube-java-heap-space-issue/build/sonar/.sonartmp/eslint-bridge-bundle/package/custom-rules6992961896990013309
Error when running: 'node -v'. Is Node.js available during analysis?
Sensor CSS Rules [javascript] (done) | time=1612ms
Sensor ThymeLeaf template sensor [securityjavafrontend]
Sensor ThymeLeaf template sensor [securityjavafrontend] (done) | time=1ms
Sensor Serverless configuration file sensor [security]
0 Serverless function entries were found in the project
0 Serverless function handlers were kept as entrypoints
Sensor Serverless configuration file sensor [security] (done) | time=6ms
Sensor AWS SAM template file sensor [security]
Sensor AWS SAM template file sensor [security] (done) | time=2ms
Sensor javabugs [dbd]
Reading IR files from: /home/jenkins/workspace/_sonarqube-java-heap-space-issue/build/sonar/ir/java
No IR files have been included for analysis.
Sensor javabugs [dbd] (done) | time=1ms
Sensor JavaSecuritySensor [security]
Reading type hierarchy from: /home/jenkins/workspace/_sonarqube-java-heap-space-issue/build/sonar/ucfg2/java
Read 2070 type definitions
Reading UCFGs from: /home/jenkins/workspace/_sonarqube-java-heap-space-issue/build/sonar/ucfg2/java

Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
06:45:28.466904 Building Runtime Type propagation graph
06:45:35.596776 Running Tarjan on 48628 nodes

Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
06:45:39.892461 Tarjan found 48539 components

Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
06:45:51.687115 Variable type analysis: done
06:45:52.293134 Building Runtime Type propagation graph

Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
06:46:03.324251 Running Tarjan on 48621 nodes

Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube
06:46:12.805894 Tarjan found 48532 components

Expiring Daemon because JVM heap space is exhausted
Exception in thread "Daemon client event forwarder" java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.addConditionWaiter(AbstractQueuedSynchronizer.java:1896)
	at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2114)
	at java.base/java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:458)
	at org.gradle.launcher.daemon.server.exec.DaemonConnectionBackedEventConsumer$ForwardEvents.getNextEvent(DaemonConnectionBackedEventConsumer.java:72)
	at org.gradle.launcher.daemon.server.exec.DaemonConnectionBackedEventConsumer$ForwardEvents.run(DaemonConnectionBackedEventConsumer.java:59)
Expiring Daemon because JVM heap space is exhausted

> Task :sonarqube FAILED
:sonarqube (Thread[Execution worker for ':',5,main]) completed. Took 4 mins 27.61 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonarqube'.
> Java heap space