Skip to content
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

Allow signaling shutdown during startup lifespan event when using Trio #213

Closed
wants to merge 2 commits into from

Conversation

seidnerj
Copy link
Contributor

@seidnerj seidnerj commented Apr 12, 2024

Without this, a failure that's triggered during the startup phase does not prompt aborting of the startup process and the server proceeds to finish loading and wait for incoming requests.

… during startup

error after shutdown should display exception text, if exception group contains only one exception - unpack it (Trio)
@seidnerj seidnerj changed the title שׁllow signaling shutdown during startup lifespan event when using Trio Allow signaling shutdown during startup lifespan event when using Trio Apr 12, 2024
@pgjones
Copy link
Owner

pgjones commented May 25, 2024

I'm not sure what you are trying to achieve here? I'm also fairly certain the ASGI spec does not allow a shutdown message during startup.

@seidnerj
Copy link
Contributor Author

In some scenarios the server encounters an exception during its startup phase (e.g. trying to fetch some configuration data or similar, without which the various routes cannot function etc.).

In the current code, even though such an exception basically means that the server is not functional, the server proceeds to finish loading then wait for incoming requests. The change I'm proposing allows such an exception to lead to a proper failure of the server instead of it proceeding as if nothing happened (which leads to a running, but "broken" server).

This is a real-life scenario we are facing. In our case, certain things must happen on server startup otherwise things won't work as expected in which case we need the service to fail.

@pgjones
Copy link
Owner

pgjones commented May 27, 2024

In some scenarios the server encounters an exception during its startup phase

This should trigger the startup failure message (lifespan.startup.failed), which would lead to the server shutting down rather than serving requests. Do you know if that is being sent?

@seidnerj
Copy link
Contributor Author

From real life experience, it seems not - the server proceeds to load and starts waiting for requests. I even tested this with a simple "raise Exception()" scenario and it behaved the same way.

@pgjones
Copy link
Owner

pgjones commented May 27, 2024

The ASGI app should change that Exception into the failed message - which one are you using?

@seidnerj
Copy link
Contributor Author

I am using Quart Trio with hypercorn

@pgjones
Copy link
Owner

pgjones commented May 28, 2024

bfb0877 should fix this, will be in next patch release.

@pgjones pgjones closed this May 28, 2024
@seidnerj
Copy link
Contributor Author

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants