Sonar scanner constantly ran out of heap space

Must-share information (formatted with Markdown):

  • which versions are you using:
    ** Sonar-developer 7.9.1 (on linux) (postgresql database)
    ** Sonar-scanner 4.0.0.1744-linux

  • what are you trying to achieve:
    Scanning a C++ / C# git repository

  • what have you tried so far to achieve this:
    With this command (to be sure JAVA has enough memory (computer has 6GB of physical RAM):
    NODE_OPTIONS=–max_old_space_size=4096 sonar-scanner -Dsonar.projectKey=analyzer -Dsonar.sources=. -Dsonar.host.url=http://localhost:9000 -Dsonar.login=f2b52504198a68b160fe52c1928c89ad9a5c3173 -Dsonar.ce.javaOpts="-Xmx3062m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m -Xms128m -XX:+HeapDumpOnOutOfMemoryError" -X

Every-time it fails with a heap space problem:
Error stream:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/home/xavier/.sonar/cache/a89f1943fc75b65becd9fb4ecab8d913/sonar-tsql-plugin.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte,int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
10:59:38.941 ERROR: Error during SonarQube Scanner execution
java.lang.OutOfMemoryError: Java heap space
at org.sonarsource.analyzer.commons.xml.XmlFilePosition.shift(XmlFilePosition.java:83)
at org.sonarsource.analyzer.commons.xml.XmlFilePosition.shift(XmlFilePosition.java:62)
at org.sonarsource.analyzer.commons.xml.XmlFilePosition.moveAfterClosingBracket(XmlFilePosition.java:109)
at org.sonarsource.analyzer.commons.xml.XmlParser.visitEndElement(XmlParser.java:198)
at org.sonarsource.analyzer.commons.xml.XmlParser.parseXml(XmlParser.java:133)
at org.sonarsource.analyzer.commons.xml.XmlParser.(XmlParser.java:68)
at org.sonarsource.analyzer.commons.xml.XmlFile.getNamespaceUnawareDocument(XmlFile.java:129)
at org.sonar.java.checks.xml.hibernate.DatabaseSchemaUpdateCheck.scanFile(DatabaseSchemaUpdateCheck.java:36)
at org.sonarsource.analyzer.commons.xml.checks.SonarXmlCheck.scanFile(SonarXmlCheck.java:44)
at org.sonar.plugins.java.XmlFileSensor.scanFile(XmlFileSensor.java:121)
at org.sonar.plugins.java.XmlFileSensor.lambda$scanFile$2(XmlFileSensor.java:114)
at org.sonar.plugins.java.XmlFileSensor$$Lambda$960/0x00000001008ac040.accept(Unknown Source)
at java.base/java.util.HashMap$Values.forEach(Unknown Source)
at org.sonar.plugins.java.XmlFileSensor.scanFile(XmlFileSensor.java:112)
at org.sonar.plugins.java.XmlFileSensor.execute(XmlFileSensor.java:86)
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.lambda$execute$1(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.sensor.ModuleSensorsExecutor$$Lambda$923/0x000000010087a440.run(Unknown Source)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:400)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:395)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:358)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)

Do you have any idea how to fix it?

Hi @xavier_paquet,

it seems like that it is during analysing file externals/ThirdParty/OpenTK.3.0.1/lib/net20/OpenTK.xml which seems to be huge. Is it intentional to analyze externals directory?

I would suggest you to refine the sonar.sources folder or to exclude some folders using sonar.exclusions. For more info see https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/.

Limitation done, now it works.
Thanks.

But it’s still strange that the scanner fails to parse this xml file (for your information it’s size is 28.1MB) with a currently defined memory limitation set to 4GB of RAM.

Hi @xavier_paquet,

indeed strange.

I see 3GB, not 4GB, would you be able to just run a test with a 5.5GB of -Xmx out of curiosity?

It fails the exact same way.

In all case (working or not with 5.5GB limitation); There’s something fishy to not be able to parse an XML file with 109x the file size in RAM usable.