I am using Jenkins to run some system tests.
Those tests write 18-20 MB printouts to the standard output.
Jenkins job is configured to run with 2048 MB max heap size.
Strangely enough, when these printouts are turned on, jenkins goes OutOfMemoryError (out of heap space).
It is definitely the printouts which cause the problem. Without them, all works fine.
What troubles me, how 20 MB of text cause the whole process to be OutOfMemory.
I already have increased the heap size from 1 GB to 2 GB, but without any result.
Without the prints, on 1GB max heap size all tests work fine.
Here the exception:
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2786)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:44)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:42)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:42)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:42)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:42)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:42)
at java.io.PrintStream.write(PrintStream.java:430)
at org.apache.maven.surefire.util.TeeStream.write(TeeStream.java:42)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:202)
at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:263)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:106)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:190)
at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:111)
at java.io.PrintStream.write(PrintStream.java:476)
at java.io.PrintStream.print(PrintStream.java:619)
at java.io.PrintStream.println(PrintStream.java:756)
...
Does anyone know some sort of configuration of Jenkins, that a lot of prints to the System.out (20 MB of them) won’t cause the OutOfMemory to occur?
Clarification: I don’t want to debug Jenkins, I am not a Jenkins developer. I use Jenkins to run system tests using JUnit on my application as CI.
Try starting jenkins with “-XX:+HeapDumpOnOutOfMemoryError” JVM argument, that should give you a dump file to analyze whenever you get the out of memory exception.
EDIT —
I think I may have something for you.
First of, the surefire plugin by default forks a new JVM for running tests, and this JVM does not inherit JVM properties of the maven JVM, i.e. if you’ve set the maven process to have 2048MB Max Heap, it will not be set for the JVM forked by the surefire plugin.
So for setting JVM args of the forked JVM, use the ‘argLine’ property of the surefire plugin. That way you’ll be able to set the Max heap for the forked JVM and not the maven JVM.
Secondly, It looks like the surefire plugin redirects the stdout/stderr and keeps the contents of stuff written to these 2 streams in memory, that’s why you may be running out of memory.
So you can also try setting ‘redirectTestOutputToFile’ property to ‘true’, that way all sdtout goes to a file, may be that will avoid storing the stream contents in memory,
Or try setting the forkmode=’always’, that way it will fork one JVM per test-class, keeping the memory consumption from piling up, one test after another.
Hope one of these helps you in your issue.