Fix: lifespan teardown masks startup failures#273
Open
carlosplanchon wants to merge 1 commit into
Open
Conversation
When any lifespan startup step failed (unreachable DB, bad credentials, ...), the finally block ran close_cache()/close_rate_limiter() unconditionally. Closing a component that never initialized raises (close_cache raises BackendNotFoundError because the backend was never registered), and that exception propagates from the finally block, burying the real startup error at the top of the log. Observed live: both a DNS failure and a wrong DB password surfaced as "Backend 'redis' is not available". Track which components actually initialized and only close those. The enabled/isinstance checks move from the teardown to the flags, so the happy path closes exactly what it closed before. Adds a regression test: a failing create_tables must surface its own RuntimeError, not a teardown exception (fails without the fix, with the exact BackendNotFoundError seen in the field). Signed-off-by: Carlos Andrés Planchón Prestes <carlosandresplanchonprestes@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If startup fails midway (e.g. unreachable DB), the finally block calls close_cache() on a never-initialized backend, which raises BackendNotFoundError and buries the real error at the bottom of the log (hit this twice in the field: a DNS failure and a bad DB password both surfaced as 'Backend redis is not available'). Fix: track which components initialized and close only those. Includes a regression test that fails without the fix.