Originally posted by karimkalimu March 21, 2024
Description
I recently updated to Uvicorn 0.29.0 and encountered a significant issue where child processes spawned by my FastAPI application are not being terminated upon a graceful shutdown. This behavior seems to be specific to the latest version of Uvicorn, as everything worked as expected prior to the update. Despite trying various configurations and explicitly using the --timeout-graceful-shutdown option, these child processes persist, becoming orphaned and reassigned to PID 1 once the main Uvicorn process is killed.
Environment
Uvicorn Version: 0.29.0
Operating System: CentOS 7
FastAPI Version: 0.100.0
Python Version: 3.10.13
Expected Behavior
I would expect all child processes, especially those flagged with daemon=True, to terminate alongside the main process during a graceful shutdown.
Actual Behavior
Instead, the child processes do not terminate as anticipated. They become orphaned and are reassigned to PID 1, persisting beyond the termination of the Uvicorn process.
Steps to Reproduce
Launch a Uvicorn server hosting a FastAPI application that spawns child processes.
Initiate a graceful shutdown of the Uvicorn server.
Notice that the child processes fail to terminate and are instead reassigned to PID 1.
Additional Context
This issue was not present in earlier versions of Uvicorn.
The observed behavior was consistent across two separate systems, both running CentOS 7.
All implicated child processes were configured with daemon=True.
Seeking Insights and Suggestions
Has anyone else encountered this issue with the most recent update of Uvicorn? I'm curious to know if this is an identified bug, if there are any known workarounds, or if perhaps there's a configuration detail I might be overlooking. Additionally, if this behavior indicates a potential bug introduced in Uvicorn 0.29.0, I'm hoping this discussion can aid in identifying and rectifying the issue.
Any insights, advice, or shared experiences would be greatly appreciated. Thank you in advance for your help!
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too