wildfly-extras / wildfly-jar-maven-plugin

WildFly Bootable JAR
https://docs.wildfly.org/bootablejar/
Apache License 2.0
57 stars 40 forks source link

[9.x] Fix dev-watch tests server shutdown #399

Open jfdenise opened 3 months ago

jfdenise commented 3 months ago

It has been reported failing test execution on Windows of some DevWatch test. Although the test is passing, the test fails when shutting down the server.

I also updated the DevWatchTestCase to remove another instability.

I suspect the server process shutdown hook to not be run on Windows. We have 2 shutdown in //, with one of the two receiving an exception when sending :shutdown , this exception causes abrupt termination of the server process (On Windows it seems not yet fixed (very old but seems still the case: https://bugs.openjdk.org/browse/JDK-8056139) that in turn will not run its shutdown hooks: https://github.com/wildfly-extras/wildfly-jar-maven-plugin/blob/main/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/DevWatchBootableJarMojo.java#L1301)

If the test was not calling a shutdown of the server in // with the DevWatchGoal shutdown, I suspect that we shouldn't observe the issue.

If a failure occurs, calling process.destroy is the right thing to do. We want the process to end, in Dev Mode having the installation directory to be deleted is needed but is not that strict. We should add a WARN trace. I logged:

https://github.com/wildfly-extras/wildfly-jar-maven-plugin/issues/398

We have 4 processes:

In the Test process:

When the test is done. First shutdown the server asynchronously (:shutdown) Then write a file to have the mvn process to exit Then wait 60 seconds for the mvn process to exit If after 60secs it has not exited, fail the test ==> What we observe

In the mvn process: The process has detected that it needs to exit (presence of the file) It exists Shutdown hook to shutdown the server is run

If an exception is thrown when calling server :shutdown (perhaps because of the shutdown, initiated by the test), process.destroy is called (https://github.com/wildfly-extras/wildfly-jar-maven-plugin/blob/main/plugin/src/main/java/org/wildfly/plugins/bootablejar/maven/goals/DevWatchBootableJarMojo.java#L1301)

On Windows process.destroy will make the process to exit without giving time to the shutdown hook to run.

Then it wait 60secs for the server to delete the installation (based on a marker file). ==> We observe that it waited and the server dir was not deleted

In the server process: When shutdown is received, shutdown hook are run and cleanup of the server installation is fired in a new process (Only on windows due to file lock)

In the cleanup process: Clean the file and exit This one seems not started.