I have a Maven project, which builds 6 separate Maven projects in Jenkins. The problem I face is that over the time the project build fails giving the 137 error code:
ERROR: Maven JVM terminated unexpectedly with exit code 137
The project could be built successfully using same Maven goals in the console, but in Jenkins it fails. By restarting Jenkins the problem can be resolved.
I have some static array lists. These lists are used for some test cases. Could this be a memory leak?
Jenkins can use Maven as its build tool.
In the Jenkins dashboard (Home screen), click Manage Jenkins from the left-hand side menu. Then, click on 'Configure System' from the right hand side. In the Configure system screen, scroll down till you see the Maven section and then click on the 'Add Maven' button. Uncheck the 'Install automatically' option.
I was running into the same behavior on our build server. The error is IMHO not associated with the maven memory settings (i.e. MAVEN_OPTS
) but rather with the memory of the underlying (Linux) machine itself (which Jenkins runs on).
The (rejected) Jenkins issue https://jenkins-ci.org/issue/12035 gives more detail on this matter:
For reference the status code 137 (128 + 9) typically means (can differ between flavours of unix). That the process was terminated by receipt of a signal. In this case signal 9 which is SIGKILL and unblockable kill.
If this is the case the underlying machine/OS needs more virtual memory. This can be added by either adding physical memory or swap space as appropriate.
You should try to increase the virtual memory of your machine.
Note:
This also explains why a Jenkins restart (temporarily) fixes the issue.
I believe you should increase the values of the memory settings - in MAVEN_OPTS
on the Jenkins machine, e.g.
MAVEN_OPTS=-Xmx1.5G -XX:MaxPermSize=0.7G
If you machine has at least 2 processors and 4GB memory, your JVM will not only grab 1GB at startup but will turn -server mode, meaning memory will be retained for performance sake (source). If you have few JVMs running at the same time (several application components, maven builds etc.) you can easily get into low memory. And one of you JVM may be killed by Linux OOM Killer because you are low on resources on the machine.
Reduce memory footprint of your process which is directly impacted by jvm default Xmx, which most probably is far from what jvm actually need.
Give it additional java command line options
-Xmx256m -XX:MaxPermSize=512m
or configure system variable
MAVEN_OPTS=-Xmx256m -XX:MaxPermSize=512m
MaxPermSize have no use for java 8+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With