-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tweak lifespan spec to require propagating exceptions thrown from lifespan tasks after 'lifespan.startup.complete'
#276
Comments
some other ideas: A new eventPerhaps there should be an additional event - A sentinel BaseExceptionor there could be a: class LifespanFailure(BaseException):
pass and lifespan tasks could: try:
with anyio.create_task_group() as app.tg:
...
except Exception as e:
raise asgiref.LifespanFailure from e New asgi servers could extract the |
I do agree something needs to happen here - it's important to have explicit failure - but not a huge fan of the |
I'd like to be able to propagate exceptions before startup complete too, but that's a bigger spec change. Eg if my task is cancelled I won't be able to send "lifespan.startup.failed" |
So the specific behaviour you would want to change is that the ASGI server swallows any exceptions during startup:
To have a specific exception that does stop the server? I think we can very reasonably support that in a backwards-compatible way, then. |
starlette Eg if importantly: if |
here's an issue where this spec violation bites: https://gitlab.com/pgjones/hypercorn/-/merge_requests/56/diffs |
'lifespan.startup.complete'
'lifespan.startup.complete'
I've been looking into this issue recently for Litestar and it would be great to continue the conversation. Like others, we have a lifespan context manager that is entered on "lifespan.startup", and exited on "lifespan.shutdown". User's can do anything within this context, including spinning up asynchronous tasks. We even document it for that purpose (ref):
and starlette seems to promote it for similar (ref):
If an exception is raised within that context but after we have sent "lifespan.startup.complete", should we raise it, emit "lifespan.shutdown.failed", or catch it, log it and keep the lifespan task running? We currently send "lifespan.shutdown.failed" and then re-raise the exception, however servers continue to serve after this (tested this against uvicorn, granian, hypercorn). |
currently in quart-trio a failure in the app.nursery is swallowed and the web server continues unabated
https://gitlab.com/pgjones/quart-trio/-/issues/21
once an ASGI app acknowledges a lifespan request (with a
lifespan.startup.complete
event) the server should treat failures in that task as fatal.Note: Now that Starlette supports trio, this is currently making writing a Starlette TaskGroup middleware a challenge
The text was updated successfully, but these errors were encountered: