-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OS Signal handling and fiber interruption #9321
Comments
hey @mlhales on what kind of OS and JVM are you experiencing this on? |
I'm on Windows 10, running Java 21 also, specifically the Amazon Coretto open jdk build. 21.0.3 |
I just tried a couple of different JDK versions as well, with the same results. I went back to 11.0.25.9.1, and forward to 21.0.5.11.1 the most recent, and got the same behavior again, correct exit with ZIO 2.1.11, and keeps running with ZIO 2.1.12 |
Also to be clear, in both cases the fiber dump is written to the console, it's just that it keeps running after the dump, still printing the "Hello, fiber!" message. |
Ok I can reproduce it on Windows!
will try to dig more tomorrow |
/bounty $250 |
|
/attempt #9321
|
@clarzte @mlhales Do you mind to test my PR solution? I have no access to Windows and it will be great to check out the PR ruling towards direction of solving this reproducer made by @clarzte |
@Saturn225 it didn't fix it |
@clarzte Can you post repoducer to check it out to reproduce it on Windows/Linux? I will checkout with my friends desktop and examine the logs and fix the things Or else any detailed logs from the reproducer :) |
@Saturn225 I used the reproducer the OP provided.
|
/attempt #9321
|
Note The user @Saturn225 is already attempting to complete issue #9321 and claim the bounty. We recommend checking in on @Saturn225's progress, and potentially collaborating, before starting a new solution. |
💡 @clarzte submitted a pull request that claims the bounty. You can visit your bounty board to reward. |
I think that this fixed the problem by introducing a bug =) Before merging you should see if it does the same thing by not registering the SIGINT handler at all. It looks to me like registering a signal handler for SIGINT, makes it so the JVM then does not run the shutdown hooks, if the SIGINT handler does not shut down the JVM. This lets the application decide if it wants to keep running or not. Look at these examples in plain Scala. The first correctly runs the shutdown hook, and exits with a 130.
This one, registers a SIGINT handler, and when run, the handler is called, but the shutdown hook is not, and the JVM keeps running.
So I think in the pull request, trying to register using the string "SIGINT" instead of "INT" makes it so the signal handler registration fails, but this fixes the issue, because the shutdown hook still runs. Before, when the correct signal handler, registered with the "INT" string runs, then the signal handler is fired, which just dumps the fibers to the console, but the shutdown hook doesn't run. So either we should just not register for SIGINT at all, or if we do, we need to do more than just dump the fibers, we need to actually request the runtime to shutdown. |
🎉🎈 @clarzte has been awarded $250! 🎈🎊 |
I've had several problems with this in the past, and it has returned again with the latest 2.1.12 version.
My understanding is when the JVM receives a signal from the OS, like a sigint or sigterm, that the ZIO runtime has subscribed to those, and attempts to interrupt the running fibers for an orderly shutdown. I have had problems in the past where fibers on attemptBlocking or fibers that were forkDaemon's will keep running, and prevent the application from exiting, requiring the JVM process to be forced to exit with a sigkill.
I have structured my application very carefully, to make sure that I don't do those things, and in ZIO 2.1.11, it shuts down cleanly (albeit with some ugly fiber messages to the console) with a 130 exit code upon sigint from IntelliJ. This is nice because when you use the stop button in IntelliJ, it shuts down cleanly. And even more importantly, when the application is deployed as a service on Windows using nssm, or as a systemd service on Linux, the default way of stopping the service, sending it a sigterm, will mean the service stops correctly and quickly.
I upgraded to ZIO 2.1.12 and this stopped working again. I've had it work correctly in the past, and also not, it seems to have been variable from version to version.
I made a minimal example that maybe somebody could turn in to a test? For me, this exits correctly with an exit code 130 upon a sigint from IntelliJ under ZIO 2.1.11, but does not exit and keeps running under ZIO 2.1.12 and requires a sigkill to exit with an exit code -1.
The text was updated successfully, but these errors were encountered: