OutOfMemoryError when running sonarscanner on github actions

  • ALM used : GitHub
  • CI system used: Github actions
  • Scanner command used when applicable (private details masked)

sonar-scanner -X
–define project.settings=ncs/nrf/sonar-project-nativeposix.properties
–define sonar.coverageReportPaths=coverage.xml
–define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}

  • Languages of the repository : C
  • Only if the SonarCloud project is public, the URL : SonarCloud
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
20:19:09.211 DEBUG: Found package.json: /__w/sdk-nrf/sdk-nrf/ncs/modules/lib/uoscore-uedhoc/package.json
Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space
	at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
	at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
20:31:54.781 DEBUG: The worker thread exited with code 1
20:32:05.194 DEBUG: The bridge server shut down
20:33:31.956 INFO: Hit the cache for 0 out of 0
20:33:31.957 INFO: Miss the cache for 0 out of 0
20:33:32.835 INFO: ------------------------------------------------------------------------
20:33:32.835 INFO: ------------------------------------------------------------------------
20:33:32.835 INFO: Total time: 15:51.026s
20:33:32.914 ERROR: Error during SonarScanner execution
java.lang.OutOfMemoryError: Java heap space
20:33:32.914 INFO: Final Memory: 122M/420M
20:33:32.914 INFO: ------------------------------------------------------------------------


I started getting OutOfMemoryError in the last few couple of days of run on my github workflow. The only thing I did was to start using a newer version of sonarsource/sonarcloud-github-c-cpp action (v2.0.2). I read in the community that this can be fixed by increasing sonar.ce.javaopts . But I cant find ouf the correct value to use when running on github actions (using github hosted runners). Can someone help?

Here are two examples of the failure.

Hey there.

It looks like the OutOfMemory issue occurs during Javascript/Typescript analysis (and you only have 2 files indexed with the javascript language).

To get you unblocked, could you try adding **/*.js to your sonar.exclusions?

Thanks for responding Colin. I tried that and it does not help.

Here is the fix I did.workflow: sonarcloud: Fix out of memory exception. · balaji-nordic/sdk-nrf@d89fbd8 · GitHub

And here is the workflow run after that change.

It looks like a different issue:

Download https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
Downloading 'https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip'
curl: (6) Could not resolve host: sonarcloud.io

The file is downloading fine for me right now. Can you run it again?

Oh. I do not see that issue in the link I provided above (Although that has also been an issue lately. Will keep that out of this thread). Here is what I see.

Adding following line to sonar-project.properties file resolved my issue.

SONAR_RUNNER_OPTS=“-Xmx3062m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m”

I believe that is equivalent to doing

sonar.ce.javaopts="-Xmx3062m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m"

in the properties file. It does not seem to help me. Is it important that the environment variable needs to be set?

sonar.ce.javaOpts won’t have any effect – and is purely a server-side variable. The issue here appears to be with the scanner.

It looks like one file is being analyzed with .mjs, so you could add that to your exclusion as well.

I think this all ultimately has to do with an ongoing incident where our Javascript/Typescript analyzer is requiring more memory… you should be able to avoid it by excluding these files, but hopefully a better fix is incoming. :crossed_fingers:

That did it. Thanks a lot :slight_smile: Looking forward to a fix for this.

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