Sending SIGTERM to parent process when running with --workers hangs indefinitely
See original GitHub issueChecklist
- The bug is reproducible against the latest release and/or
master
. - There are no similar issues or pull requests to fix it yet.
Describe the bug
When running uvicorn with multiple workers, sending a SIGTERM ie kill -15 ppid
there’s no graceful shutdown and the process hangs indefinitely on https://github.com/encode/uvicorn/blob/ff4af12d6902bc9d535fe2a948d1df3ffa02b0d3/uvicorn/supervisors/multiprocess.py#L57
To reproduce
Expected behavior
A graceful shutdown
Actual behavior
Debugging material
Environment
- OS / Python / Uvicorn version: just run
uvicorn --version
Running uvicorn 0.12.2 with CPython 3.8.6 on Linux
- The exact command you’re running uvicorn with, all flags you passed included. If you run it with gunicorn please do the same. If there is a reverse-proxy involved and you cannot reproduce without it please give the minimal config of it to reproduce.
Additional context
originally discovered in https://github.com/encode/uvicorn/issues/364 and mistakenly taken for a docker issue, it’s in fact a SIGTERM issue afaiu
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (9 by maintainers)
Top Results From Across the Web
Bash: Why does parent script not terminate on SIGINT when ...
When I start script1.sh from a terminal, and then use Ctrl + C to send SIGINT to its process group, the signal is...
Read more >Issue 9205: Parent process hanging in multiprocessing if ...
msg109585 ‑ (view) Author: Greg Brockman (gdb) Date: 2010‑07‑08 20:00
msg109867 ‑ (view) Author: Jesse Noller (jnoller) * Date: 2010‑07‑10 12:52
msg109885 ‑ (view) Author:...
Read more >Why is SIGINT not propagated to child process when sent to ...
Sending the signal to the parent process does not seem to work. Why is the signal not propagated to cat when sent to...
Read more >SIGHUP for "session has gone away", not SIGTERM/SIGKILL
process (systemd-run should work, users need to get used to this). ... system should hang forever because sending a SIGKILL after SIGTERM is...
Read more >ProcessManagement - Greg's Wiki
(On some systems, running processes can also change their own names. ... preferable to your sending SIGTERM to some innocent process.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yep we got a problem with SIGTERM, and not just in docker: it was discovered 1st as a docker issue because it’s the default signal sent to exit a container , but the issue exists without containers, so the digging performed in #364 that ended up in a potential fix in #620 was not the right move.
I think #853 is the correct way to handle multi process exits cleanly, it is just too big to review, cant find a way not time to slice it properly
As far as I can tell, calling
terminate()
just sends a SIGTERM to each of the child processes, which then handle it appropriately. As it stands the parent process eats the SIGTERM and so the children never see it and don’t know to terminate.PR inbound!