apache / apache/maven-surefire

[SUREFIRE-2114] Surefire is going to kill self fork JVM. The exit has elapsed 30 seconds after System.exit(0).

Open
#2,797 4 comments 2 reactions 0 assignees View on GitHub
bug priority:critical
Dominant language
Java
Stars
461
Forks
588
Avg merge
1d 8h
Merged PRs (30d)
19

Description

**[Kamalpreet](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER288713)** opened **[SUREFIRE-2114](https://issues.apache.org/jira/browse/SUREFIRE-2114?redirect=false)** and commented

Hi Team, 

I'm using maven surefire plugin (Latest Version) to execute tests on two testing frameworks (e.g, jUnit, jBehave).

Have tried to implement parallelisation by spawning couple of Threads which in turn create processes to execute surefire jar, taking it from -

```java
ManagementFactory.getRuntimeMXBean().getSystemProperties().get("sun.java.command");
```

Code snippet to show process creation - **CustomRunner.java**

```java
  void run() {
    ProcessBuilder processBuilder = new ProcessBuilder(commandArray);
    Map environment = processBuilder.environment();
    environment.put("platformIndex", String.valueOf(platformIndex));
    try {
        processBuilder.inheritIO();
        Process p = processBuilder.start();
        LOGGER.info("Is Alive {} {}", p.isAlive(), LocalTime.now());
        int statusCode = p.waitFor();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
```

**EntryPoint.java**

```java
for (int i = 0; i < 3; i++) {
   Thread thread = new Thread(new CustomRunner(commandArray, String.valueOf(i)));
   thread.start();
   threadList.add(thread);
 }
threadList.forEach(thread -> {
   try {
     thread.join();
   } catch (InterruptedException e) {
     throw new RuntimeException(e);
   }
});
    
System.exit(exitcode);
```

After running two or sometimes three processes in corresponding Threads, the process execution got stuck on p.waitFor();

Then the process exits after 30 secs and with error message "Surefire is going to kill self fork JVM. The exit has elapsed 30 seconds after System.exit(0)." resulting in Build Failure (sometimes it doesn't) though the tests have passed in their respective processes.

Seems like surefire execution is stuck in some processes. Could you please let me know what can be the possible reasons for it and how to mitigate this? Tried extending the ForkedProcessTimeoutInSeconds to few minutes but no luck.

Any help is much appreciated.

---

**Attachments:**
- [surefire.log](https://issues.apache.org/jira/secure/attachment/13048655/surefire.log) (_63.74 kB_)

Contributor guide

Open the contributing guide

Research direction

Start with the CustomRunner.java and EntryPoint.java snippets, then reproduce the case that starts two or three Surefire processes and blocks at p.waitFor(). Read surefire.log alongside the 30-second timeout behavior; done means identifying why the forked processes remain stuck and documenting or implementing a mitigation that avoids the build failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.