user12258871
user12258871

Reputation: 11

Spring-Boot 2.2.0 process fails to terminate when launched in debug mode

When running spring-boot 2.2.0 in debug mode in both Eclipse 2019-06 and IntelliJ 2019.2, attempts to terminate the process via the IDE look like they kill the process (per the IDE), however, the java process is still running (verified by ps -ef | grep java).

When running non debug mode in Eclipse, the process can be terminated but Eclipse displays a message stating "terminate failed".

I've tried all sorts of older post options including: -Dspring-boot:run.fork=false -Dfork=false

Running spring at cmd line using mvn spring-boot:run terminates normally with ctrl-c.

I'm not using any spring plugins in Eclipse. I'm using open jdk 11.0.3+7.

Everything worked normally in spring-boot 2.1.7, 2.1.8 and 2.1.9

Is this possibly a bug in spring-boot 2.2.0?

Upvotes: 1

Views: 2693

Answers (2)

Maze
Maze

Reputation: 1

I had the same problem when I moved to 2.2.0 (+ JDK 11).

As @guidadic said : since 2.2.0, the JVM is forked by default.

Unfortunately for me, if I disable forking, I lose some features, like colour in the console, which worked before with no fork. In addition, forking allows to use DevTools, with live reloading, which is pretty interesting.

After a long and hazardous search on Internet, I found out a solution on a non related Stackoverflow answer somewhere (I lost the link).

In your main method, get your application context from the run method, and then open a console scanner.
When you will press the red square to kill your app in Eclipse, the scanner throws an exception : the Eclipse managed (visible) thread is the one linked to the console, so the scanner doesn't like that you dare to stop it.
You just need to catch it to exit from the application :

log.info("Press 'Enter' to terminate");
try (Scanner scanner = new Scanner(System.in)) {
    scanner.nextLine();
}
finally {
    log.info("Exiting");
    System.exit(SpringApplication.exit(context));
}

Additionally, if you press 'enter' in your Eclipse console, it will exit your application and terminate all the application JVMs.

Upvotes: 0

guidadic
guidadic

Reputation: 31

With Spring Boot v2.2.0.RELEASE, JVM process forking is enabled by default when starting from the maven plugin:

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes#fork-enabled-by-default-in-maven-plugin

At this time, Intellij's maven plugin in 2019.2 and earlier versions don't appear to associate the child process to the debugging session and the IDE is even unable to shutdown the process once started.

None of the solutions in the references below worked for me. The only way I found to disable forking was to set the flag directly in the spring-boot-maven-plugin in the pom.xml like so:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <!-- disable process forking that is enabled by default in spring-boot 2.2.0.RELEASE and higher -->
        <fork>false</fork>
    </configuration>
</plugin>

Afterward, I can now right-click on spring-boot:run, select debug, and the debugger connects to the right child process.

Additional references:

https://github.com/spring-projects/spring-boot/issues/18638

https://github.com/spring-projects/spring-boot/issues/18706

Upvotes: 3

Related Questions