-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
Fix graceless ctrl C #1269
Fix graceless ctrl C #1269
Conversation
Simple and elegant... though it's hard to say if it works. |
Thanks @dimaqq. I'm cool with adding a test (implementation suggestions welcomed) if I get buy-in on this PR from a maintainer (e.g. @Kludex or @euri10)... otherwise I don't want to waste my time on that. But so far everyone has been strangely quiet! And a mysterious "hold" label has appeared to boot. 🧐 Maintainers' thoughts welcomed... Easy enough to see that it works, however, by contrasting ctrl-C behavior with/without this tweak (just beware of any testing via class monkeypatching in the main process... the monkeypatch won't persist to the child process. That bit me once.) |
Currently, we have the following behavior:
This PR proposes to change
The one I've implemented there shifts the forceful shutdown to a third SIGINT/TERM received instead. For now this solution makes sense, as it just solves the issue in hands. but I'm more willing to use the strategy I propose on #1205 at some point, so I'm not sure if we should go with this for now, and then change later, or just go with that, as it also solves the issue we have. In any case, I need to confirm that another member will be willing with my proposal on #1205. @euri10 What do you think? As for the |
@Kludex changing to a 3rd sigint/sigterm would work as well, of course. However... that has the (IMO) undesirable effect of requiring 3 CTRL+C's to force-shutdown an app running in terminal! As far as I know, there are really only 3 use-cases that anyone cares about here:
I don't think anyone cares about force-shutdown after 2 SIGTERMs. Where is the use-case for that? The only things sending SIGTERMs are the process supervisors, which generally have their own force-kill logic (e.g. docker, kubernetes) so uvicorn doesn't really need to worry about handling force kills in those cases anyway (and these frameworks certainly don't signal a second time to be cute... it is SIGKILL after the first attempt has timed out.) TL;DR: treating SIGINT & SIGTERM as exactly the same always (including for the purposes of a force-shutdown) may be slightly misguided, since CTRL C sends a SIGINT, and not a SIGTERM, to the foreground process group of the terminal, and chances are, any "supervising" process (including a human in a 2nd shell tab 😜) will not bother sending a 2nd SIGTERM if the first one failed, but rather a SIGKILL (whereas CTRL+C twice to force exit is fairly standard & convenient). |
re:
Should |
I've thought about this, and reread the alternative solution. I've come to the conclusion that it's more practical to have this in place. About the future PR that I've mentioned, I don't think it makes sense to mention that here, as we have a long way before that is merged. But... I can make that PR work with this solution anyway, so that point was useless. Also, even if a change is needed, we can do that on the process manager itself instead of changing the handler on the
Not really, because Thanks for sticking with me here. 👍 |
None that I can think of, but someone could have done that, as it was possible. Also, we don't document that. |
Alternative to #1165. Fixes #1160.
Edit by @Kludex: Closes #1165