Getting "HttpClient-1-SelectorManager" java.lang.OutOfMemoryError: Metaspace in Github Actions

  • ALM used: GitHub
  • CI system used: GitHub Actions
  • Scanner command used: ./gradlew -Pprod --info sonar
  • Languages of the repository: Java
  • Sonarqube Gradle plugin version: 4.0.0.2929
  • Error observed:
> Task :stock-take-service:sonar FAILED
Error: Exception in thread "HttpClient-1-SelectorManager" java.lang.OutOfMemoryError: Metaspace
Expiring Daemon due to JVM Metaspace space being exhausted
Could not stop build 'buildSrc'.
java.lang.OutOfMemoryError: Metaspace
Could not stop Service DefaultPlanExecutor.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
java.lang.InternalError: java.lang.OutOfMemoryError: Metaspace

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.6.1/userguide/command_line_interface.html#sec:command_line_warnings
Expiring Daemon due to JVM Metaspace space being exhausted
	at java.base/java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:413)
	at java.base/java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:315)
	at java.base/java.lang.invoke.InnerClassLambdaMetafactory.buildCallSite(InnerClassLambdaMetafactory.java:228)
	at java.base/java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:341)
	at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:134)
	at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:315)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:281)
	at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:271)
	at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:383)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.OutOfMemoryError: Metaspace
  • What I’ve tried:
org.gradle.jvmargs=-XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=512M

I’ve tried adding the above settings in my gradle.properties. Didn’t work.
I also haven’t set JAVA_OPTS or SONAR_SCANNER_OPTS in my environment variables

What if you bump these values up further? Like to 2G.

I’ve tried 2048 but I’m still getting the same error

org.gradle.jvmargs=-XX:MetaspaceSize=2048M -XX:MaxMetaspaceSize=2048M

It seems to be failing at this step:
Analyzing 245 ucfgs to detect vulnerabilities

The last run took about 5 hours at this step before I canceled it, so there’s definitely something here.

Reading UCFGs from: /home/runner/work/.../build/sonar/ucfg2/java
15:01:31.870465761 Building Runtime Type propagation graph
15:01:31.931473284 Running Tarjan on 1332 nodes
15:01:31.944346984 Tarjan found 1332 components
15:01:31.950022116 Variable type analysis: done
15:01:31.954522221 Building Runtime Type propagation graph
15:01:31.969434869 Running Tarjan on 1332 nodes
15:01:31.970554395 Tarjan found 1332 components
15:01:31.972253435 Variable type analysis: done
Analyzing 245 ucfgs to detect vulnerabilities.

Expiring Daemon due to JVM Metaspace space being exhausted

Hello @lewimuchiri ,

Thank you for reaching out to us. I’ll try my best to help you.

Metaspace out of memory is not a standard error at all. We need to gather more information to understand its source.

First, would it be possible for you to relaunch the same analysis, activating the sonar debug logs? Adding sonarProperty("sonar.debug", "true") in your build.gradle should do it. Then you can share with me in a private message the logs.

I suspect that the GitHub environment might be the culprit. It could be interesting to rerun the analysis on a local machine rather than on GitHub. Let me know if it is possible for you.

Hi Thomas,

Thank you for your reply. I have generated the logs; how can I send you a private message? (i.e., I can’t see that option here). Maybe share your email?

Hi Lewis,

Thanks for sharing the logs.
If I read them correctly, it seems the build failed at another spot in the sonar analysis before the security analysis, which starts roughly with the logs Reading UCFGs from ... as you shared before. So it looks like the OOM is unrelated to a particular step in the sonar analysis.

A few random ideas:

  • If you don’t run the sonar analysis, do you still have the metaspace OOM?
  • Did you upgrade the Gradle Sonar plugin version or the SonarQube version lately?

Hi Thomas,

If I don’t run the sonar task, it works fine. I don’t get the OOM error.
Yes, I recently upgraded the Sonar plugin to the latest version, which is 4.0.0.2929. However, I still attempted to do the sonar scan with the old version 3.5.0.2730 and I got the same OOM error

Hi @lewimuchiri,

No other ideas come to my mind. We have already encountered this problem and the following command did solve it :

Maybe you could check that there is enough memory on the container used to run your GitHub actions and then, try again the above command.

I’ll redirect this thread to other SonarSourcers who may have other ideas.

Cheers,

1 Like

I finally managed to fix this issue by changing the name I had used for the plugin properties block from sonarqube to sonar.

For example:

becomes

This is what finally worked for me

1 Like