-
-
Notifications
You must be signed in to change notification settings - Fork 399
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
fix: asgi lifespan msg after lifespan context exception #3315
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3315 +/- ##
=======================================
Coverage 98.26% 98.26%
=======================================
Files 322 322
Lines 14718 14720 +2
Branches 2342 2342
=======================================
+ Hits 14462 14464 +2
Misses 117 117
Partials 139 139 ☔ View full report in Codecov by Sentry. |
d2fc354
to
0666740
Compare
An exception raised within an asgi lifespan context manager would result in a "lifespan.startup.failed" message being sent after we've already sent a "lifespan.startup.complete" message. This would cause uvicorn to raise a `STATE_TRANSITION_ERROR` assertion error due to their [check for that condition][1]. This PR modifies `ASGIRouter.lifespan()` so that it sends a shutdown failure message if we've already confirmed startup. This is consistent with [starlette's behavior][2] under the same conditions. [1]: https://github.com/encode/uvicorn/blob/a2219eb2ed2bbda4143a0fb18c4b0578881b1ae8/uvicorn/lifespan/on.py#L115-L117 [2]: https://github.com/encode/starlette/blob/4e453ce91940cc7c995e6c728e3fdf341c039056/starlette/routing.py#L744-L745
0666740
to
a34f92a
Compare
Quality Gate passedIssues Measures |
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3315 |
An exception raised within an asgi lifespan context manager would result in a "lifespan.startup.failed" message being sent after we've already sent a "lifespan.startup.complete" message. This would cause uvicorn to raise a `STATE_TRANSITION_ERROR` assertion error due to their [check for that condition][1]. This PR modifies `ASGIRouter.lifespan()` so that it sends a shutdown failure message if we've already confirmed startup. This is consistent with [starlette's behavior][2] under the same conditions. [1]: https://github.com/encode/uvicorn/blob/a2219eb2ed2bbda4143a0fb18c4b0578881b1ae8/uvicorn/lifespan/on.py#L115-L117 [2]: https://github.com/encode/starlette/blob/4e453ce91940cc7c995e6c728e3fdf341c039056/starlette/routing.py#L744-L745 (cherry picked from commit fac641a)
An exception raised within an asgi lifespan context manager would result in a "lifespan.startup.failed" message being sent after we've already sent a "lifespan.startup.complete" message. This would cause uvicorn to raise a
STATE_TRANSITION_ERROR
assertion error due to their check for that condition, if asgi lifespan is forced (i.e., with$ uvicorn test_apps.test_app:app --lifespan on
).E.g.,
This PR modifies
ASGIRouter.lifespan()
so that it sends a shutdown failure message if we've already confirmed startup. This is consistent with starlette's behavior under the same conditions.Description
Closes