Apologies - this is my first time here. I can't f...
# community-support
j
Apologies - this is my first time here. I can't find an answer for this anywhere. I'd like to know how I can override this hardcode here DefaultWorkerProcessBuilder.java#L251-L251, for GradleWorkerMain threads - specifically for tests? I'm getting OOM on the worker when running unit tests. I've tried setting DEFAULT_JVM_OPTS, JAVA_OPTS, GRADLE_OPTS, modifying DEFAULT_JVM_OPTS in gradlew/gradlew.bat, and have tried stuff like this in my build.gradle.kts:
Copy code
tasks.withType<JavaExec>().configureEach {
    jvmArgs("-Xmx1024m")
}

tasks.withType<Test>().configureEach {
    jvmArgs("-Xmx1024m")
}
...and nothing takes. Thanks.
c
I assume the worker is a github worker? I've never had to tweak... are you using the gradle setup action?
what's the real error message? do you have a build scan?
that heap size seems quite small, I'd be surprised if java itself didn't run out of memory
but when you say OOM is that java or the OS killing it
sounds like the OS
j
This is actually on my local MacOS, but we are running into the same problem on GHA build too.
I'll need to run it again. It has been giving me random ClassNotFoundExceptions today. I need to do a clean and rerun to get a repro.
c
if it's failing on your macos WITHOUT trying to constrain the memory I'd say you have a memory leak and need to start tracing the memory
j
It is throwing OutOfMemory exception
c
what is it
j
Running unit tests. Here you go ex:
Copy code
~/csvol/git/wavebid-a2o/wavebid-a2o-service:1195> ./gradlew test 
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "mysql-cj-abandoned-connection-cleanup"
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at open/src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 838
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at open/src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 838
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at open/src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 838
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at open/src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 838

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "DefaultDispatcher-worker-14"

Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "DefaultDispatcher-worker-12"
*** java.lang.instrument ASSERTION FAILED ***: "!errorOutstanding" with message can't create name string at open/src/java.instrument/share/native/libinstrument/JPLISAgent.c line: 838
c
looks like java, have you tried setting the memory to like 4g and seeing what it does?
j
Yes.
c
ok, I'd recommend looking at it with jprofiler or something like jprofiler
j
The upper Java runtimes all take the parameters we set. And those seem to be okay. It is the workers that are hardwired to -Xmx512m that give us trouble.
c
yeah, idk, sorry
I don't play around with the worker api
j
Another, just to document here. This is the one I was getting consistently yesterday...
Copy code
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 3.
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:65)
	at java.base@21/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base@21/java.lang.reflect.Method.invoke(Method.java:580)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:92)
	at jdk.proxy1/jdk.proxy1.$Proxy4.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:200)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:132)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:103)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:63)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:121)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: java.lang.OutOfMemoryError: Java heap space
i
Hi, you can increase the heap allocation for the test process using:
Copy code
maxHeapSize = "1G"
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:maxHeapSize
jvmArgs
does not include system properties and the minimum/maximum heap size. Full example:
Copy code
dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter:5.7.1")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.named<Test>("test") {
    useJUnitPlatform()

    maxHeapSize = "1G"

    testLogging {
        events("passed")
    }
}
j
Thanks. I will try that.
That worked. I'm seeing the worker come up with that allocation now:
Copy code
501 99080 97512   0  1:43PM ??         0:37.68 /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/bin/java -Dorg.gradle.internal.worker.tmpdir=... -javaagent:... -Xmx1G -Dfile.encoding=UTF-8 -Duser.country=US -Duser.language=en -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 3'
👍 1
Thank you
e
I work w/ James. Nice side effect is that tests are over twice as fast now.