Skip to content
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

RTS workaround converting SIGTERM into SIGINT #3641

Merged
merged 2 commits into from
Mar 3, 2022

Conversation

DavidEichmann
Copy link
Contributor

This is important for graceful shutdown, cleaning up resources in
bracket statements.

Fixes #1697

@DavidEichmann
Copy link
Contributor Author

I should actually throw to the main thread rather than raise SIGINT. That's what the RTS does. I should also upstream this to GHC (see TopHandler).

@DavidEichmann
Copy link
Contributor Author

I'm working on a GHC patch that'll make this the default behavior of the RTS https://gitlab.haskell.org/DavidEichmann/ghc/-/tree/davide/sigterm

Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a couple comments

(Signals.CatchOnce $ do
runThreadIdMay <- deRefWeak runThreadIdWk
case runThreadIdMay of
Nothing -> return ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not a putStrLn "thread id no longer exists" or something to that effect?

runThreadIdMay <- deRefWeak runThreadIdWk
case runThreadIdMay of
Nothing -> return ()
Just runThreadId -> killThread runThreadId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also put some output here signalling that the thread was successfully killed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was lifted from GHC. We use a weak pointer so that the main thread can be garbage collected. If doRefWeak returns Nothing, then the main thread must have already exited. I can only imagine that might be possible if the main thread had shut down by some other means and a SIGTERM happened just after that. In that case I'd expect the process to exit gracefully any way, so simply doing nothing here (return ()) sounds correct. Is that convincing or do you still think we should output some message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. in the case that the main thread is still live, you're asking if we should show a message still. There is already a message the appears: Shutting down.., but I dono for the life of me where it's coming from :-/ Do you think that message is enough, or if we need more?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^ Fair points. I think it's fine as is.

This is important for graceful shutdown, cleaning up resources in
`bracket` statements.

Fixes #1697
@DavidEichmann
Copy link
Contributor Author

I've responded to comments by @newhoggy in #3670

@Jimbo4350 Jimbo4350 self-requested a review March 3, 2022 11:22
@DavidEichmann
Copy link
Contributor Author

bors merge

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Mar 3, 2022

Build succeeded:

@iohk-bors iohk-bors bot merged commit 79bf77f into master Mar 3, 2022
@iohk-bors iohk-bors bot deleted the davide/sigterm_handler branch March 3, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] - Node should cleanly exit on SIGTERM
3 participants