[BUG] Exit at startup failure on multiple workers
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 the startup fails, either on reload mode or multiple workers, the main process is not terminated.
To reproduce
Application:
# test.py
from fastapi import FastAPI
app = FastAPI()
@app.on_event("startup")
def startup():
raise Exception("Hi")
uvicorn test:app --workers 2
# or
uvicorn test:app --reload
Expected behavior
All the processes (parent and children) should be terminated.
Actual behavior
❯ uvicorn test:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [40026] using watchgod
INFO: Started server process [40028]
INFO: Waiting for application startup.
ERROR: Traceback (most recent call last):
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 540, in lifespan
async for item in self.lifespan_context(app):
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 481, in default_lifespan
await self.startup()
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 518, in startup
handler()
File "/home/marcelo/Development/./test.py", line 7, in startup
raise Exception("Hi")
Exception: Hi
ERROR: Application startup failed. Exiting.
After this log, it hangs forever. On the reload
, it doesn’t prevent the failure from happening multiple times if you modify a watched file. See:
❯ uvicorn test:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [40674] using watchgod
INFO: Started server process [40676]
INFO: Waiting for application startup.
ERROR: Traceback (most recent call last):
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 540, in lifespan
async for item in self.lifespan_context(app):
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 481, in default_lifespan
await self.startup()
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 518, in startup
handler()
File "/home/marcelo/Development/./test.py", line 7, in startup
raise Exception("Hi")
Exception: Hi
ERROR: Application startup failed. Exiting.
WARNING: WatchGodReload detected file change in '['/home/marcelo/Development/test.py']'. Reloading...
INFO: Started server process [40734]
INFO: Waiting for application startup.
ERROR: Traceback (most recent call last):
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 540, in lifespan
async for item in self.lifespan_context(app):
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 481, in default_lifespan
await self.startup()
File "/home/marcelo/anaconda3/envs/uvicorn/lib/python3.8/site-packages/starlette/routing.py", line 518, in startup
handler()
File "/home/marcelo/Development/./test.py", line 7, in startup
raise Exception("Hi")
Exception: Hi
ERROR: Application startup failed. Exiting.
In the case of multiple workers, it just hangs forever.
Environment
- OS / Python / Uvicorn version: Running uvicorn 0.14.0 with CPython 3.8.10 on Linux
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (11 by maintainers)
Top Results From Across the Web
Troubleshoot role instance startup failure in Azure Cloud ...
This article discusses how to troubleshoot startup failures in Azure Cloud ... Option 2: Use PowerShell to view the role instance status.
Read more >How to debug gunicorn failure issues? (Worker failed to boot)
Try running with --preload as an argument to gunicorn_django - it should show you the error the workers are having when starting. See...
Read more >432 startup failure post-mortems - CB Insights
After failing to sell off its English learning courses, it shut down for good and laid off its workforce of around 120 employees....
Read more >Start Failed, Internal error: recovering IDE to the working state ...
There are multiple possible causes for this issue: broken or incompatible plug-in, corrupted IDE installation files, failed patch update, broken caches or ...
Read more >Critical Issues Addressed in PAN-OS Releases
Bugs Affected Platform(if any). /Affected Version Description (release note)
PAN‑92564 8.0.0‑8.0‑8, 8.1.0
PAN‑86882 8.0.0‑8.0.7. and all older Mainlines
PAN‑81990 PA‑5220,PA‑5250. /. 8.0.4 Multiple DP restarts by...
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
Just want to point out that this is still an issue on
0.17.0.post1
.Yes.