SonarQube Anslysis fails with OutOfMemoryError: Java heap space at step Running Tarjan

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube Developer Edition 8.4.1.35646)
  • what are you trying to achieve Run Code Analysis on a pull request
  • what have you tried so far to achieve this Increased memory to 8GB

Below is a log of errors we’re getting when running a SonarQube analysis. On different Pull Requests, the process works sometimes, but we are encountering more frequent failures

...    
2020-10-21T16:29:16.1380913Z INFO: Sensor CSharpSecuritySensor [security]
2020-10-21T16:29:16.1381268Z INFO: Reading type hierarchy from: E:\116C\13\.sonarqube\out\ucfg_cs2
2020-10-21T16:29:17.5777358Z INFO: Read 4730 type definitions
2020-10-21T16:29:17.6361451Z INFO: Reading UCFGs from: E:\116C\13\.sonarqube\out\ucfg_cs2
2020-10-21T16:29:32.3454708Z INFO: 17:29:32.339 Building Type propagation graph
2020-10-21T16:29:40.8132763Z INFO: 17:29:40.809 Running Tarjan on 186774 nodes
2020-10-21T16:30:08.1214943Z INFO: ------------------------------------------------------------------------
2020-10-21T16:30:08.1215885Z INFO: EXECUTION FAILURE
2020-10-21T16:30:08.1216321Z INFO: ------------------------------------------------------------------------
2020-10-21T16:30:08.1216635Z INFO: Total time: 7:01.489s
2020-10-21T16:30:08.1985165Z INFO: Final Memory: 24M/234M
2020-10-21T16:30:08.1986196Z INFO: ------------------------------------------------------------------------
2020-10-21T16:30:08.1999181Z ##[error]ERROR: Error during SonarScanner execution
2020-10-21T16:30:08.2000268Z ERROR: Error during SonarScanner execution
2020-10-21T16:30:08.2005443Z ##[error]java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Unknown Source)
	at java.util.Arrays.copyOf(Unknown Source)
	at java.util.ArrayList.grow(Unknown Source)
	at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
	at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
	at java.util.ArrayList.add(Unknown Source)
	at com.sonar.C.A$_B.A(na:600)
	at com.sonar.C.A$_B.<init>(na:190)
	at com.sonar.C.A$_B.<init>(na:740)
	at com.sonar.C.A.B(na:1294)
	at com.sonar.security.analysis.A.A.B.<init>(na:2262)
	at com.sonar.security.analysis.L.A(na:2376)
	at com.sonar.security.G.execute(na:1523)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
2020-10-21T16:30:08.2008211Z java.lang.OutOfMemoryError: Java heap space
2020-10-21T16:30:08.2008496Z 	at java.util.Arrays.copyOf(Unknown Source)
2020-10-21T16:30:08.2008782Z 	at java.util.Arrays.copyOf(Unknown Source)
2020-10-21T16:30:08.2009087Z 	at java.util.ArrayList.grow(Unknown Source)
2020-10-21T16:30:08.2009411Z 	at java.util.ArrayList.ensureExplicitCapacity(Unknown Source)
2020-10-21T16:30:08.2009733Z 	at java.util.ArrayList.ensureCapacityInternal(Unknown Source)
2020-10-21T16:30:08.2010051Z 	at java.util.ArrayList.add(Unknown Source)
2020-10-21T16:30:08.2010306Z 	at com.sonar.C.A$_B.A(na:600)
2020-10-21T16:30:08.2010583Z 	at com.sonar.C.A$_B.<init>(na:190)
2020-10-21T16:30:08.2010847Z 	at com.sonar.C.A$_B.<init>(na:740)
2020-10-21T16:30:08.2011500Z 	at com.sonar.C.A.B(na:1294)
2020-10-21T16:30:08.2012403Z 	at com.sonar.security.analysis.A.A.B.<init>(na:2262)
2020-10-21T16:30:08.2012889Z 	at com.sonar.security.analysis.L.A(na:2376)
2020-10-21T16:30:08.2013338Z 	at com.sonar.security.G.execute(na:1523)
2020-10-21T16:30:08.2013741Z 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
2020-10-21T16:30:08.2014900Z 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
2020-10-21T16:30:08.2015992Z 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:62)
2020-10-21T16:30:08.2016544Z 	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
2020-10-21T16:30:08.2017045Z 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
2020-10-21T16:30:08.2019886Z ##[error]at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:388)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:384)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:353)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
2020-10-21T16:30:08.2021662Z 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
2020-10-21T16:30:08.2022158Z 	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:388)
2020-10-21T16:30:08.2022651Z 	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:384)
2020-10-21T16:30:08.2023182Z 	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:353)
2020-10-21T16:30:08.2023985Z 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
2020-10-21T16:30:08.2024503Z 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
2020-10-21T16:30:08.2026091Z ##[error]at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
2020-10-21T16:30:08.2027255Z 	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:144)
2020-10-21T16:30:08.2027763Z 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:137)
2020-10-21T16:30:08.2028242Z 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:123)
2020-10-21T16:30:08.2030173Z ##[error]at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
ERROR:
2020-10-21T16:30:08.2031493Z 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
2020-10-21T16:30:08.2031902Z 	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
2020-10-21T16:30:08.2032376Z 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
2020-10-21T16:30:08.2032828Z 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2020-10-21T16:30:08.2033181Z 	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2020-10-21T16:30:08.2033414Z ERROR: 
2020-10-21T16:30:08.2737803Z ##[error]The SonarQube Scanner did not complete successfully
2020-10-21T16:30:08.2738707Z The SonarQube Scanner did not complete successfully
2020-10-21T16:30:08.2792446Z ##[error]17:30:08.275  Post-processing failed. Exit code: 1
2020-10-21T16:30:08.2793287Z 17:30:08.275  Post-processing failed. Exit code: 1

Good evening, @nmude . Would it be possible to share with us the contents of E:\116C\13\.sonarqube\out\ucfg_cs2 folder? That would help me a lot to reproduce the problem locally. I can send you a PM, so that you could reply me privately with the files.

Hi @Dmitry_Golovinov, sure, DM me

Good morning! Have you tried increasing memory with SONAR_SCANNER_OPTS environment variable?

In order to see that this increase was successful - you can check your log files for the presence of line INFO: SONAR_SCANNER_OPTS=.... . I would recommend trying out -Xmx8G in your case (check https://docs.sonarqube.org/latest/analysis/scan/sonarscanner/). If you don’t see this line in the log file - that means that your adjustments are not effective.

Please, see related topic - SonarQube analysis hangs in the "Running Tarjan" step or throws OutofMemoryError

Also, please consider updating to the latest version of SonarQube if it’s possible.

Hi @Dmitry_Golovinov
I’ve set the Windows Environment variable SONAR_SCANNER_OPTS and restarted the server, but it still doesnt show in the logs.
I can see the value of the environment variable when I query all that are set on the server, but it isn’t being picked up.
We’ve also updated to 8.5.1.38104

Could you please try the following sequence locally on your project (I’ve crafted a simple project and checked it on my machine) ?

set SONAR_SCANNER_OPTS=-Xmx8G
SonarScanner.MSBuild.exe begin /k:"foo"
dotnet build (or MSBuild solution.sln /t:Rebuild)
SonarScanner.MSBuild.exe end

In the end you should be able to see something like:

SonarScanner for MSBuild 4.10
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
Using the supplied value for SONAR_SCANNER_OPTS. Value: -Xmx8G
Calling the SonarQube Scanner...

Thanks @Dmitry_Golovinov
We needed to set SONAR_SCANNER_OPTS in the VSTS pipeline, not on the server. Setting it on the server had no impact

1 Like