Java Heap space Memory Issue with latest sonar-java plugin

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube : CE 7.9.2, Scanner 4.2.0.1873, Plugin (sonar-java plugin - 6.3.2.22818, and any relevant extension)
  • what are you trying to achieve - Perform code quality analysis for multi Module java Maven project
  • what have you tried so far to achieve this - We need to scan around 2612 java files for analysis across three modules. Out of three modules , two of them are smaller modules and they have a total of 90 files altogether. The issue is occuring while analysing the module with more java files (2524 files). We are getting java heap space issue and upon investigation we found that there was a change in sonar-java plugin which got updated to 6.3.2.22818. When we reverted this plugin to earlier working version 5.13.1.18282 , we are not seeing this memory issue any more. Can anyone help find the root cause on why we are getting issue with latest sonar-java plugin ? PS : There is enough memory available in server (around 8GB) and even we have tried increasing the heap space for sonar.ce.javopts property, but even then we are facing the same issue with latest version of Sonar-java plugin

Hi Rajaganesh,

With each plugin upgrade, there are often new rules being added, specially now on the security side, which may require more memory. However, we need to make sure this is either a potential memory leak on our side or an expected issue due to memory really lacking on your system.

Could you please share here:

  • The full log where the error is being shown. If this happens on the server side, then this should be the ce.log file.
  • The sonar.ce.javaOpts, sonar.web.javaOpts and sonar.search.javaOpts settings you were initially using.
  • The size in lines of code of the project you are scanning.
  • Is your server machine exclusively dedicated to SonarQube, or is it running other potentially memory-hungry processes (e.g. database etc). Are you launching the scan from a separate machine?

Regards,
Daniel

Hi Daniel,
Thanks for responding so quickly. This is my first time seeking help from a community forum and I am indeed amazed to see the swift response. Please find the answers to your question below.

  • The full log where the error is being shown. If this happens on the server side, then this should be the ce.log file. - I work for a client project and I am not allowed to share anything outside of my client network or in a public website. I know how you might be feeling now , but if there is anything you can tell me , that I can look in the log file I can get that for you.
  • The sonar.ce.javaOpts, sonar.web.javaOpts and sonar.search.javaOpts settings you were initially using. - 1) sonar.web.javaOpts=-Xmx512m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError 2) sonar.ce.javaOpts=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError (-Xmx value was initially 512mb and we have changed to 1Gb which is working fine with earlier version of sonar-java plugin) 3) sonar.search.javaOpts - unfortunately i cannot find this configuration in the configuration properties file of sonarqube. Is there a recommended/standard vaue for this option ?
  • The size in lines of code of the project you are scanning. - 315K lines of code. yes to some extent our project is considered to be a big :slight_smile:
  • Is your server machine exclusively dedicated to SonarQube, or is it running other potentially memory-hungry processes (e.g. database etc). Are you launching the scan from a separate machine? Our server runs Sonarqube server , opensource jenkins and during analysis I cannot see any drop in memory and availalbe memory is in the range of 4 - 7 GB.

And yes we have our scanner binary placed in another machine in which we are running our Jenkins build pipeline and triggering the sonar analysis as part of the pipeline. This pipeline has different stages and before the pipeline starts there is a free memory of 21GB and when the build stage completes the available free memory is 12GB and when the sonar analysis starts and executes it further drops to 4GB or so and as said earlier during the scanning of java files in the bigger module memory issue is observed. If I exclude that particular java file and start the analysis it is stuck in the subsequent file of same module with same memory issue. At that point of time where the issue occurs, the free memory is close to 2GB.

All the servers that we are using are linux servers.

I hope I have given almost all the details , Please let me know if you need any further details

Hi Rajaganesh,

Unfortunately, without the ability of sharing logs, it will be very difficult to assist you properly. You can share these privately if possible.

If the error is seen on the CI Jenkins pipeline, and the error is output on the scanner log that runs within that pipeline, then this is not a problem of the SonarQube server running out of memory and therefore, the sonar.*.javaOpts options on the server’s sonar.properties file won’t have any impact here. The problem is that the scanner runs out of memory.

You mention you have Jenkins installed on the same server as SonarQube server. At the same time, you mention that the analysis is done on another machine which also runs a Jenkins pipeline. At this point I am a bit confused: do you actually have another Jenkins installation in that other machine?

Cheers,
Daniel

Hi Daniel,

Sorry to have caused the confusion. The server where sonarqube runs is also the jenkins master server. The Server where I am running the sonar analysis(by executing the sonar scanner binary) via pipeline is the slave agent to Jenkins master. My entire pipeline runs on the slave machine.

I will try my level best to get the logs, but just wanted to make sure if you still need the ce.log as I run the scanner in one machine and my sonarqube runs on a separate server. Also if you can share some insights on taking java heap dump during the analysis(via SONAR_SCANNER_OPTIONS ) which gives me .hprof file, I will analyze and see if the memory leak is really happening at the server side.

Hi Rajaganesh,

No need of the ce.log as the problem is on the scanner side. You should try incrementing the memory allocated to the SonarScanner. As pointed out in the SonarScanner for Maven Troubleshooting, set the memory allocated to your scanner initially to 512m, then 1G, then 2G etc (using MAVEN_OPTS, as you are using the SonarScanner for Maven) if you still get the Java Heap out of memory error.

At the same time, make sure to monitor memory consumption in the machine running the scanner.

Hope this helps, regards,
Daniel