Docker->Maven->Failsafe->Surefire starting fork fails with “The forked VM terminated without properly saying goodbye. VM crash or System.exit called?”

不羁岁月 提交于 2019-11-30 08:46:48

Try downgrading to Surefire 1.18.1. I ran into this issue tonight and spent a couple hours on it, so far it's not easily apparent why newer builds of Surefire break under Docker.

* Update *

I was having an issue with Alpine linux, but when using an Ubuntu or Debian base image everything was fine. So something within 1.21 is breaking compatibility with certain operating systems.

I have encountered the same issue in the following environment: docker image from alpine 3.7, maven surefire plugin version 2.21.0.

The root cause of that is described at SUREFIRE-1422: surefire tries to use ps -p to check forked process. The solution for me was to add procps:

RUN apk add --no-cache procps

I know it's been a while but will add my solution to the problem which took me more than a day to FIX.

Problem: I'm running my integration tests in the PaaS in a docker container and have no control on the memory allocation for my process. the default behavior is for failsafe/surfire to fork a JVM and run the tests on it. I could not find a way to control the memory allocation for that forked JVM and tests kept failing with the error "Error occurred in starting fork" also saw "The forked VM terminated without saying properly goodbye docker" in the logs depending on which version of failsafe I was trying.

Solution: My solution was to disable forking of the JVM and have all the tests run in the same JVM as the main maven process, now this may not be the ideal solution for many but it would work if you can only control the max memory allocation of the main maven process.

To disable forking it's as simple as setting the forkMode in the config:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <configuration>
        <forkCount>0</forkCount>
    </configuration>

.....

UPDATE: Since giving this solution it seems like you can now pass params to the forked JVM so shouldn't need the earlier solution.

From the maven docs under Forked Test Execution:

With the argLine property, you can specify additional parameters to be passed to the forked JVM process, such as memory settings. System property variables from the main maven process are passed to the forked process as well. Additionally, you can use the element systemPropertyVariables to specify variables and values to be added to the system properties during the test execution.

https://maven.apache.org/surefire/maven-failsafe-plugin/examples/fork-options-and-parallel-execution.html

We suddenly experienced the exact same issue, but only on our CI/CD pipeline (gitlab). The error message was:

error occurred in starting fork, check output in log
Process Exit Code: 1
org.apache.maven.surefire.booter.SurefireBooterForkException: 
The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

It turned out that it was related to a new version of the OpenJDK docker image.

Setting the useSystemClassLoader property to false solved the issue:

   <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>${maven-surefire-plugin.version}</version>
    <configuration>
      <includes>
        <include>**/*Test.java</include>
      </includes>
      <useSystemClassLoader>false</useSystemClassLoader>
    </configuration>
  </plugin>

We had the same issue while using spring boot with surefire version 2.21.0 on alpine with docker (zenika/alpine-maven). Like mentioned before, downgrading to 2.18.1 might be an option and solved the forked vm termination issue, but triggered new issues with incompatibilities between different slf4j versions. So we did an explicit upgrade to surefire version 2.22.1, which solved the issue in our case.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
</plugin>

Just hit the same problem when building inside maven:3.5.4-jdk-8 using surefire 2.21.0. Upgrading surefire didn't help either, but disabling forking finally did the trick.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.1</version>
    <configuration>
        <forkCount>0</forkCount>
    </configuration>
</plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!