Memory error running Code Analysis

I am trying to run an analysis of a project with 375K lines of code.

  • versions used : SonarQube Dev Ed. 8.5.1.38104
  • error observed: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread “JGit-WorkQueue”
  • The SonarQube analysis is being run from within an AzureDevOps Pipeline
    • Analysis works if I exclude the unit tests projects (and hence have no code coverage)
    • If I include the unit tests I get the following error
##[error]Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "JGit-WorkQueue"
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "JGit-WorkQueue"
INFO: ------------------------------------------------------------------------
INFO: EXECUTION FAILURE
INFO: ------------------------------------------------------------------------
INFO: Total time: 7:12.906s
INFO: Final Memory: 9M/37M
##[error]ERROR: Error during SonarScanner execution
ERROR: Error during SonarScanner execution
INFO: ------------------------------------------------------------------------
##[error]java.lang.OutOfMemoryError: Java heap space
java.lang.OutOfMemoryError: Java heap space
##[error]ERROR:
ERROR:
##[error]The SonarScanner did not complete successfully
The SonarScanner did not complete successfully
##[error]16:47:30.976 Post-processing failed. Exit code: 1
16:47:30.976 Post-processing failed. Exit code: 1
##[error]The process 'E:\Agent\_work\_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.17.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe' failed with exit code 1

I have upped the Compute Engine memory to 8192m in the sonar.properties file

sonar.web.javaOpts=-Xmx8192m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
sonar.ce.javaOpts=-Xmx8192m -Xms128m -XX:+HeapDumpOnOutOfMemoryError

and I can see this memory setting in SonarQube admin console

Do I just keep adding more memory or is there another setting to consider?

Note: other than this issue the SonarQube server is behaving as expected

Having reread the documentation I am trying setting the environment variable SONAR_SCANNER_OPTS=-Xmx1024m on the build box

1 Like

Just to complete the details of the solution…

As am running SonarQube within an Azure DevOps pipeline the easiest way to set an environment variable is to just set a pipeline variable as the build agent makes all pipeline variables available as environment variables on at runtime.

So as I was using YML, I set a variable within the build job

  - job: build
      timeoutInMinutes: 240
      variables:
        - name: BuildConfiguration
          value: 'Release'
        - name: SONAR_SCANNER_OPTS
          value: -Xmx4096m
      steps:

I found I had to quadruple the memory allocated to the scanner. Once this was done my analysis completed

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.