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

Make shutdown cause/trigger available #16976

Closed
xtaixe opened this issue May 4, 2021 · 7 comments · Fixed by #26752
Closed

Make shutdown cause/trigger available #16976

xtaixe opened this issue May 4, 2021 · 7 comments · Fixed by #26752
Labels
area/arc Issue related to ARC (dependency injection) kind/enhancement New feature or request
Milestone

Comments

@xtaixe
Copy link

xtaixe commented May 4, 2021

Description

CLI apps might need to know if shutdown is due to normal exit or due to Ctrl+C/SIGINT, so there should be a way to distinguish those (and maybe other signals too).

Implementation ideas

Enhance the ShutdownEvent with some kind of "cause" or "trigger" property or maybe have different events to observe for different shutdown triggers.

@xtaixe xtaixe added the kind/enhancement New feature or request label May 4, 2021
@geoand geoand added area/arc Issue related to ARC (dependency injection) and removed triage/needs-triage labels Jul 13, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jul 13, 2022

/cc @manovotn, @mkouba

@manovotn
Copy link
Contributor

manovotn commented Jul 13, 2022

That's not a bad idea, we could add some information into the event, but I have no clue when it comes to determining the cause of shutdown. Looking at Quarkus code, we have StartupContext and ShutdownContext but that doesn't seem very helpful as those are just auto closeables.

@geoand any idea how/if we could achieve that?

@geoand
Copy link
Contributor

geoand commented Jul 13, 2022

It's actually pretty easy in Quarkus code to determine whether or not the shutdown came from a SIGINT as io.quarkus.runtime.ApplicationLifecycleManager$ShutdownHookThread is the Shutdown Hook involved.

Ultimately io.quarkus.runtime.StartupContext#close gets called (no matter what the source of the shutdown is) so if we have some state in there we could propagate it

@manovotn
Copy link
Contributor

CLI apps might need to know if shutdown is due to normal exit or due to Ctrl+C/SIGINT, so there should be a way to distinguish those (and maybe other signals too).

@xtaixe What exactly do you consider a "normal" exit for CLI app? I.e how do you quit the app in a normal way?
Also what other signals do you think are worth distinguishing? I don't see much value in telling user if it was SIGINT or SIGTERM but i might be missing something.

It's actually pretty easy in Quarkus code to determine whether or not the shutdown came from a SIGINT as io.quarkus.runtime.ApplicationLifecycleManager$ShutdownHookThread is the Shutdown Hook involved.

@geoand I saw ShutdownHookThread but that's simply invoked on every shutdown and I don't see a way to determine why shutdown happened from the thread itself.
I noticed we also have SignalHandler that can do exactly this but those seem to only be registered in native image and without certain system env set. There is probably a good reason for that too,

@geoand
Copy link
Contributor

geoand commented Jul 13, 2022

I saw ShutdownHookThread but that's simply invoked on every shutdown and I don't see a way to determine why shutdown happened from the thread itself

It's only invoked when the shutdown comes from a SIGINT, not from a normal program termination or application code initiated termination.

@xtaixe
Copy link
Author

xtaixe commented Jul 13, 2022

@manovotn

What exactly do you consider a "normal" exit for CLI app?

Maybe I didn't express that properly. I meant the program just finishes cause there's nothing more to do (e.g. ls) as opposed to keep running doing or waiting for something (e.g. tail/follow logs), which in our case is when you need to stop it using CTRL+C.

Also what other signals do you think are worth distinguishing? I don't see much value in telling user if it was SIGINT or SIGTERM but i might be missing something.

Maybe it's not worth distinguishing. In our case it's not needed, as long we can distinguish finishing from interrupted is enough. But if the information is already there maybe just provide it and let the user decide.

@manovotn
Copy link
Contributor

Right, we can only probably differentiate between normal program finish and "all else".
That is, a situation when ShutdownHookThread is not invoked (normal) and when it is invoked (SIGINT, SIGTERM, ... but also System.exit()).

I'll try to get to it later this week and put together a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants