Search code examples
javajunitjvmjmockit

Intermittent JUnit error - java virtual machine connection refused


I'm getting intermittent JUnit 4 errors in our Jenkins build system. The test passes after re-running it. The test is started by Maven and uses JMockit for mock objects.

The root cause of the exception comes from the VM:

Caused by: java.io.IOException: Connection refused
at sun.tools.attach.LinuxVirtualMachine.connect(Native Method)
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:124)

Anyone experienced this and found a solution?


Solution

  • Looks like its a bug in the JVM https://bugs.java.com/bugdatabase/view_bug?bug_id=6649594

    The workaround was to pass a JVM argument:

    -XX:+StartAttachListener
    

    and the tests stopped failing.