Improper error handling for lifespan protocol #8069
-
|
Describe the bug To Reproduce
The uvicorn server will log that "The lifespan protocol appears unsupported". Depending on the error, and the server configuration, the application may be left running but the server will stop sending lifespan events as a result, so the shutdown event handlers(and possibly any user-defined startup handlers) will not be triggered either. Expected behavior Environment:
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
I might actually be mixing up Kludex/starlette#488, which was recently fixed and caused a similar error to occur, with an unrelated uvicorn issue that causes it to report the same error in case of port collision regardless of the application. |
Beta Was this translation helpful? Give feedback.
-
|
just to be sure I get it right, here's what I tried with running
|
Beta Was this translation helpful? Give feedback.
-
|
Yes, in my case (on the Windows machine I'm currently using), Uvicorn in terminal 2 exits immediately with the following output. I've done some further testing and uvicorn throws the same error with a simple ASGI lifespan handler, so this issue might actually not be related to FastAPI at all, my bad. async def app(scope, receive, send):
if scope['type'] == 'lifespan':
while True:
message = await receive()
if message['type'] == 'lifespan.startup':
# Do some startup here!
await send({'type': 'lifespan.startup.complete'})
elif message['type'] == 'lifespan.shutdown':
# Do some shutdown here!
await send({'type': 'lifespan.shutdown.complete'})
return
else:
pass # Handle other types |
Beta Was this translation helpful? Give feedback.
-
|
interesting, I've seen but can't remember right now some issues related to windows and uvicor. |
Beta Was this translation helpful? Give feedback.
-
|
Closing, since this is a Uvicorn bug, not a FastAPI bug (see Kludex/uvicorn#435). |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.
Closing, since this is a Uvicorn bug, not a FastAPI bug (see Kludex/uvicorn#435).