1

In these days I added a bundle of codes to my project, Gradle build failed in Github actions, some tests throw OOM error when running Gradle test task.

The project tech stack is Spring Boot 3/R2dbc + Kotlin 1.8/Kotlin Coroutines+ Java 17(Gradle Java Language level set to 17)

The build tooling stack.

  • Local system: Windows 10 Pro(with 16G memory)/Oracle JDK 17/Gradle 7.6(project Gradle wrapper)
  • Github actions: Custom Ubuntu with 16G memory/Amazon JDK 17

After researching, we use a custom larger runner with 16G memory, and increase the Gradle JVM heap size to 8G, but it is no help.

org.gradle.jvmargs=-Xmx8g -Xms4g

We still get the following errors when running tests. But testing codes itself is not a problem, they have been passed on my local machine.

*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 827

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ClassGraph-worker-439"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ClassGraph-worker-438"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "boundedElastic-evictor-1"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ClassGraph-worker-435"
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 827

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ClassGraph-worker-433"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ClassGraph-worker-436"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ClassGraph-worker-432"

Update: After posting this question on Spring Boot and other discussion, now confirmed it was caused by classgraph. Classgraph is used by spring doc to scan and analyze the OpenAPI endpoints. If I remove spring doc from the project, it works again.

The problem is even I setup a global springdoc.packageToScan to shrink the scan scope, it still failed with OOM error.

Hantsy
  • 8,006
  • 7
  • 64
  • 109

1 Answers1

0

It looks that the error happens in a Gradle worker. Gradle executes separate JVM processes to run the tests, whose memory settings are different than main Gradle process. This by default uses 512mb.

You can do different things to solve this: either increase the heap for that worker, or reduce the amount of tests executed in each worker. You can reduce the amount in two ways: either forking multiple parallel processes per module or forking a new process each a fixed amount of tests in serial mode. Increasing the heap for the Gradle test worker might be the best, but if you have many modules executing the tests in parallel you might exhaust the total memory of your agent as well.

Please take a look to the Gradle testing documentation for more details on these options. You control all of these settings with the code below (I do not recommend applying all of these together, this is just to illustrate the options).

tasks.withType<Test>().configureEach {
    maxHeapSize = "1g"
    forkEvery = 100
    maxParallelForks = 4
}

In any case, my recommendation would be to profile the build to figure out exactly what are the processes exhausting the memory, what is the most suitable memory settings and potentially identify where is the leak that is producing this.

rolgalan
  • 1,631
  • 17
  • 34
  • I tried to add global jvm args to increase the heap side, no help. After posting this question on Spring Boot and other discussion, now it can be confirmed it is caused by classgraph scanning. Classgraph is used in [spring doc](https://springdoc.org/), remove spring doc, work again. The left is tune the spring doc config or find a replacement. – Hantsy Jan 21 '23 at 02:00