openjfx / javafx-maven-plugin

Maven plugin to run JavaFX 11+ applications
Apache License 2.0
369 stars 59 forks source link

`asyncDestroyOnShutdown` does not work / what is it supposed to do? #168

Open Marcono1234 opened 1 year ago

Marcono1234 commented 1 year ago

Version

0.0.8

Description

It appears asyncDestroyOnShutdown does not work correctly; the Maven JVM exits and the JavaFX window remains open.

The underlying issue is Apache Commons Exec EXEC-121: Because the JavaFX plugin uses the async execute method, the process is launched in a separate thread and the process destroyer is registered afterwards. However, in the meantime the JVM has already exited.

Also as side note, for you async execution you should probably prefer org.apache.commons.exec.DaemonExecutor over DefaultExecutor (see also EXEC-69). I assume your current code just happens to work for async JavaFX launching because Maven seems to explicitly call System.exit at the end, but that might be an implementation detail.

However, I don't really understand the use case for asyncDestroyOnShutdown. If it was working correctly (can be achieved by delaying Maven exit after JavaFX plugin execution), then what is happening is that the JavaFX application launches and then at some arbitrary point, when Maven exits, terminates. What is the use case for that / where would that be desired? I can mainly imagine a feature like this being useful for synchronous execution, but that currently does not exist, see #169.

Reproduction steps

  1. Clone and open https://github.com/openjfx/samples/tree/master/HelloFX/Maven locally
  2. Run
    mvn clean javafx:run "-Djavafx.async=true" "-Djavafx.asyncDestroyOnShutdown=true"

    :x: Bug: The Maven JVM exits but the application remains open

(Might depend a bit on the machine you are performing this on, since this is essentially a race condition, see description above)