question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shutdown process is broken in 0.15

See original GitHub issue

Checklist

  • 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]

image

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:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:22 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
igormcsouzacommented, Oct 12, 2021

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

1reaction
igormcsouzacommented, Nov 10, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ticket #873: 0.15.0 server throwing thread parse exception - Xpra
This happens because when we restart the sound we now restart the process, during the process shutdown things can go wrong (as per...
Read more >
shutdown process takes too long stuck in the dekstop for few ...
i count it almost 5 minutes for shutting down but for the booting time its only takes 15 second or less.
Read more >
Changelog - Prefect Docs
This hotfix release fixes an issue where the kubernetes agent would attempt to load a secret value and fail if it was not...
Read more >
How Long Does Alcohol Stay in Your System?
Alcohol is predominantly broken down by the liver, which can metabolize roughly 1 standard drink per hour for men. Factors such as age, ......
Read more >
My Computer Won't Shut Down; Now What? - Tech Masters
Step 3: After waiting for 5 to 10 minutes, power on your computer and use your normal shutdown process to turn it off...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found