Shutdown process is broken in 0.15
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
My FastAPI ASGI server cannot shutdown properly with uvicorn==0.15 while it can with 0.14
To reproduce
Setup minimal FastAPI app and add some functions with logs(prints) to shutdown event
Expected behavior
You see all logs(prints) from functions on shutdown
Actual behavior
Get ASGI 'lifespan' protocol appears unsupported.
without --lifespan on
Get error trace with --lifespan on
Debugging material
uvicorn scheduler.main:app --host=0.0.0.0 --port ${WEB_PORT:-8000} --reload --lifespan on INFO: Will watch for changes in these directories: [‘/home/dmytro/storage/chimplie/projects/raok-main/raok-scheduler’] INFO: Uvicorn running on http://0.0.0.0:8004 (Press CTRL+C to quit) INFO: Started reloader process [177653] using statreload INFO: Started server process [177655] INFO: Waiting for application startup. INFO: Tortoise-ORM started, {‘default’: <tortoise.backends.asyncpg.client.AsyncpgDBClient object at 0x7f63d4a10e50>}, {‘models’: {‘Task’: <class ‘scheduler.models.task.Task’>, ‘Aerich’: <class ‘aerich.models.Aerich’>}} INFO: Application startup complete. ^CINFO: Shutting down INFO: Finished server process [177655] ERROR: Exception in ‘lifespan’ protocol Traceback (most recent call last): File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/uvicorn/lifespan/on.py”, line 84, in main await app(scope, self.receive, self.send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py”, line 75, in call return await self.app(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/fastapi/applications.py”, line 199, in call await super().call(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/starlette/applications.py”, line 112, in call await self.middleware_stack(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/starlette/middleware/errors.py”, line 146, in call await self.app(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/starlette/middleware/cors.py”, line 70, in call await self.app(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/starlette/exceptions.py”, line 58, in call await self.app(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/starlette/routing.py”, line 569, in call await self.lifespan(scope, receive, send) File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/starlette/routing.py”, line 544, in lifespan await receive() File “/home/dmytro/.local/share/virtualenvs/raok-scheduler-hpGGYNLi/lib/python3.8/site-packages/uvicorn/lifespan/on.py”, line 135, in receive return await self.receive_queue.get() File “/usr/lib64/python3.8/asyncio/queues.py”, line 163, in get await getter asyncio.exceptions.CancelledError INFO: Stopping reloader process [177653]
Environment
- Fedora 34 / Python 3.8 / Uvicorn version: 0.15 - bug, 0.14 - ok
- command to run:
uvicorn main:app --host=0.0.0.0 --port 8000 --reload
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:22 (8 by maintainers)
Top GitHub Comments
I’m having the exactly same issue!! Here’s the code https://github.com/igormcsouza/kitty-api/blob/master/api/__init__.py
I downgrade to 0.14 just to avoid error
Even though the problem persist! I tried once more yesterday! That error at the end causes issues on my routine! I will keep on 0.14 until it is fixed!