Dealing with “Gradle Executor Failed”

This error is now observed in many of the cases, which is triggered by a JVM crash.
While JVM can crash in many scenarios, one of the most common scenarios is OutOfMemory, or Memory Leak, because of which JVM fails to allocate memory for newly created objects and crashes.

To start with run this command to set your java heap size to 1G max. You need to do it only once.
echo "org.gradle.jvmargs=-Xmx1g" >> gradle.properties

https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks002.html

In this article, we will discuss how to isolate the place where OOM. There are different reasons why OOM can occur, and we will try to find out a possible memory leak.

PS: The scenario will not be same always, so these instructions may not apply OOTB for every use case, but these can be used as a guideline.

Lets will pick up one use case for the same.

STEP 1:

You get an error like below -

Note the location of test-report and open the same. Here in this case it is - file:///tmp/external_build/reports/tests/test/index.html

STEP 2 - Get The Stack Trace

Open the HTML and see the stack trace. You will find some rows related to your code Note them down, and look into the code there.

STEP 3 - Analyse Code

Go to the code and try to locate the exception place. Like in the below image, you can see that there is some statement list.add that’s causing OOM. Its quite possible that the statement is executed in an infinite loop or part of some greedy operation.

STEP 4 - Isolate The Error With Logging.

Make a code change in the code to add a bit of logging. Similar to what we have done below.

Here, basically we are trying to check if there is any infinite loop adding to the list. we added a counter to check how many times the loop is executed.

There can be different places to add such loggers, based on your code organisation.

STEP 5 - Execute and Confirm The Hypothesis

Test failed - open the log.

file:///tmp/external_build/reports/tests/test/index.html

Explore it a little -

Go with Classes => failed class ⇒ Standard Output

Will be something like below

file:///tmp/external_build/reports/tests/test/classes/com.crio.qcharm.ds.SourceFileHandlerArrayListImplTest.html

You will find an error like this -

So this is the confirmation that you have an infinite loop in the code. Fixing the loop will help you solve the problem.

This is an FAQ candidate

Closing this topic as it has been solved by you yourself. Great job, keep working hard. if its not resolved feel free to un-mark the accepted solution to re-open the topic.