Reflex should terminate when a lifespan task fails
Describe the Enhancement you want As suggested in this discussion, I'm proposing the following enhancement:
When a lifespan task raises an exception, the whole reflex application should terminate.
My usecase: I'm using a lifespan task for some initialization (e.g. loading some configuration from a file). If this fails, the whole application is in an unusable state, so ideally it should just terminate completely. Then it would also be easy to auto-detect the failure.
Currently an exception just seems to result in the task being stopped but not affecting the application as a whole. Even using sys.exit() seems to only kill the backend with the frontend still running (so the reflex run process does not terminate, which makes it difficult to automatically detect the failure).
Alternatively, if termination is not always desired, adding some function to shut down the application would also be an option (e.g. rx.shutdown()). Then one would catch the Exception in the lifespan task and explicitly terminate reflex.
Even using sys.exit() seems to only kill the backend with the frontend still running (so the reflex run process does not terminate, which makes it difficult to automatically detect the failure).
Please note that in some production deployments (including ReflexCloud) the frontend is being exported and served as static files, so it'll never be "stopped" and killing reflex will only effectively kill the backend.
So I think that if we added an rx.shutdown() it would basically be a call to sys.exit, along with some logic to stop the frontend server as well in dev mode π€