-
Notifications
You must be signed in to change notification settings - Fork 82
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
What is the recommended way to gracefully stop a Haskell process? #119
Comments
If you need to send a specific signal, then I would recommend using the unix package directly. I'm not opposed to providing additional functions in More generally: there's no way you can depend on cleanup actions ever being run in this manner. An external process may elect to kill your process with SIGKILL, for instance, or the machine may just shut down. Generally speaking, cleanup actions are useful for maintaining invariants within a single process, like ensuring locks are releases or file descriptors freed. However, cleanup actions which will have evidence outside of the process cannot ever be relied upon to be run, regardless of SIGINT vs SIGTERM. |
Thanks for the answer. It's not really important for me to run all cleanup actions during shutdown and I understand that the program may be killed with SIGKILL. However, in 99% cases one my application will kill another my application, so in these 99% cases I have full control and I was thinking that it's better to do cleanup actions in these 99% cases.
The main difficulty is to understand how to do gracefully stop a process on Windows. We will probably try to figure out how do it (there are some recommendations here) and will submit a PR if we succeed. |
I've been looking into this as I seem to get orphaned processes when restarting with SIGTERM. I suspect Haskell only kills threads triggering process cleanups on SIGINT. |
I find this issue to be very confusing, @gromakovsky could you clarify? Is this about:
If it's about question 1, that doesn't seem to be an issue for the For point 2, the answer would be to use |
The only function to stop a process I found is
terminateProcess
.According to the documentation, on Unix systems it will send the SIGTERM signal.
I did some research and concluded that apparently when a Haskell process receives SIGTERM signal, it will not throw an exception to the main thread, but will stop everything rudely, so that, for example, second action passed to
bracket
will not be executed. That differs from SIGINT handling which causesUserInterrupt
to be thrown. I used this code to test it.But I want to kill a process gracefully, to allow
bracket
to do all cleanup actions.So I am wondering: shouldn't
process
have a function which will do it?Alternatively I can use
System.Posix.Signals
fromunix
to send SIGINT directly (and do something else on Windows). Or I can set a special handler for SIGTERM in my Haskell program which will behave akin to SIGINT.I would appreciate any recommendations.
The text was updated successfully, but these errors were encountered: