Out of Memory Exceptions

Article ID:204318364
2 minute readKnowledge base

Issue

  • Jenkins suddenly crashes

  • There was an Out of Memory (OOM) exception in your Jenkins environment.

      java.lang.OutOfMemoryError [...]

    or

      There is insufficient memory for the Java Runtime Environment to continue.

Resolution

If OutOfMemory happens, Jenkins is in the undefined behavior mode. It means that anything may fail, including mission-critical threads in the controller. As a result, it does not really make sense to investigate any other observed issue (i.e. connectivity between nodes, any plugin misbehaviour, etc.) before fixing OOM first.

Usually, this error is thrown when there is insufficient space to allocate an object in the Java heap. In this case, The garbage collector cannot make space available to accommodate a new object, and the heap cannot be expanded further. Also, this error may be thrown when there is insufficient physical memory or swap space to support the loading of a Java class. In a rare instance, a java.lang.OutOfMemoryError may be thrown when an excessive amount of time is being spent doing garbage collection and little memory is being freed.

To determine the cause of this exception. The text of the exception includes a detail message. There are different types of OOM Exception as you can see Java 11 - Understand the OutOfMemoryError Exception. From them, we would like to highlight in the Jenkins context (jenkins.log):

A. Native Memory exhausted

java.lang.OutOfMemoryError: unable to create new native thread
There is insufficient memory for the Java Runtime Environment to continue.

Solution: Memory problem: 'unable to create new native thread' Use 64 bit Java if Windows is 64 bit. 64-bit Java offers better management of memory; Decrease Java heap size (-Xmx/-Xms). This will free up more physical memory. Review other running applications and close the ones no longer needed.

B. Java Heap exhausted

java.lang.OutOfMemoryError
java.lang.OutOfMemoryError: GC overhead limit exceeded
java.lang.OutOfMemoryError: Java heap space

C. Process killed by OOM Killer

In this case, the JVM crashes. The error can be spotted in /var/log/dmesg.log:

[XXXXX] Out of memory: Kill process <JENKINS_PID> (java) score <SCORE> or sacrifice child
[XXXXX] Killed process <JENKINS_PID> (java) total-vm:XXXkB, anon-rss:XXXkB, file-rss:XXXkB, shmem-rss:XXXkB

D. PermGen Area exhausted (Java 8 and before)

java.lang.OutOfMemoryError: PermGen space