Java heap space error in sonar scanner with postgres sql on LINUX

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
  • what are you trying to achieve
  • what have you tried so far to achieve this

Hi Team,

we are running sonar scanner on our c,c++ project, while scanning on few modules the analysis get successful, however the scan report that gets generated is not uploaded.
The background tasks shows failed with teh “java heap space” error

Error Details
java.lang.OutOfMemoryError: Java heap space
at org.postgresql.util.PGbytea.toBytesHexEscaped(PGbytea.java:37)
at org.postgresql.util.PGbytea.toBytes(PGbytea.java:33)
at org.postgresql.jdbc.PgResultSet.getBytes(PgResultSet.java:2383)
at org.postgresql.jdbc.PgResultSet.getBinaryStream(PgResultSet.java:2459)
at org.apache.commons.dbcp2.DelegatingResultSet.getBinaryStream(DelegatingResultSet.java:318)
at org.apache.commons.dbcp2.DelegatingResultSet.getBinaryStream(DelegatingResultSet.java:318)
at org.sonar.db.ce.CeTaskInputDao.selectData(CeTaskInputDao.java:69)
at org.sonar.ce.task.projectanalysis.step.ExtractReportStep.execute(ExtractReportStep.java:65)
at org.sonar.ce.task.step.ComputationStepExecutor.executeStep(ComputationStepExecutor.java:81)
at org.sonar.ce.task.step.ComputationStepExecutor.executeSteps(ComputationStepExecutor.java:72)
at org.sonar.ce.task.step.ComputationStepExecutor.execute(ComputationStepExecutor.java:59)
at org.sonar.ce.task.projectanalysis.taskprocessor.ReportTaskProcessor.process(ReportTaskProcessor.java:81)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.executeTask(CeWorkerImpl.java:207)
at org.sonar.ce.taskprocessor.CeWorkerImpl$ExecuteTask.run(CeWorkerImpl.java:189)
at org.sonar.ce.taskprocessor.CeWorkerImpl.findAndProcessTask(CeWorkerImpl.java:156)
at org.sonar.ce.taskprocessor.CeWorkerImpl$$Lambda$785/222434688.apply(Unknown Source)
at org.sonar.ce.taskprocessor.CeWorkerImpl$TrackRunningState.get(CeWorkerImpl.java:131)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:83)
at org.sonar.ce.taskprocessor.CeWorkerImpl.call(CeWorkerImpl.java:51)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

sonarqube version- 7.6
sonar-scanner version - sonar-scanner-3.3.0.1492-linux
database used is postgres 9.6

I have increated the java memory under sonar scanner. properities file and gave the value as
SONAR_SCANNER_OPTS="-Xmx8192m"

also under the sonar properities the memory has been set to below
sonar.web.javaOpts =-Xmx8512m -Xms512m -XX:MaxPermSize=8192m -XX:+HeapDumpOnOutOfMemoryError

the AUTOCOMMIT is set to off under postgres sql.

still the repport is not gettign uploaded

end output of teh scanner execution is pasted below for referrence
WARN: Too many duplication groups on file thirdparty/private/cavium/usbc_gnu_src/OCTEON-SDK/bootloader/u-boot/arch/mips/cpu/octeon/cvmx/cvmx-error-init-cn52xxp1.c. Keep only the first 100 groups.
WARN: Too many duplication groups on file thirdparty/private/cavium/usbc_gnu_src/OCTEON-SDK/executive/cvmx-error-init-cn52xxp1.c. Keep only the first 100 groups.
INFO: CPD calculation finished
INFO: Analysis report generated in 12841ms, dir size=755 MB
INFO: Analysis report compressed in 43136ms, zip size=154 MB
INFO: Analysis report uploaded in 9079ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=npsoft
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AWly1M_sEQFv3_feQfsg
INFO: Executing post-job ‘Final report’
WARN: Preprocessor: 104132 include directive error(s). This is only relevant if parser creates syntax errors. The preprocessor searches for include files in the with ‘sonar.cxx.includeDirectories’ defined directories and order.
WARN: Source code parser: 167360 syntax error(s) detected. Syntax errors could cause invalid software metric values. Root cause are typically missing includes, missing macros or compiler specific extensions.
INFO: Turn debug info on to get more details (sonar-scanner -X -Dsonar.verbose=true …).
INFO: Analysis total time: 25:02.746 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 25:04.835s
INFO: Final Memory: 108M/5898M
INFO: ------------------------------------------------------------------------

Could you please assist in resolving the java heap space error. Please let me knwo which all files needs to be verified or make chaneges

Regards,
Sathish Krishnan

Hi Sathish,

This statement is contradictory. If the analysis report isn’t being uploaded, then you don’t get to the point of having a background task error. Based on the stacktrace, it seems that your memory problem is on the server side, not the scanner side. You should try increasing the server’s memory allocation (and restarting the server).

 
Ann