Skip to content

Fix: lifespan teardown masks startup failures#273

Open
carlosplanchon wants to merge 1 commit into
benavlabs:mainfrom
carlosplanchon:fix/lifespan-teardown-masking
Open

Fix: lifespan teardown masks startup failures#273
carlosplanchon wants to merge 1 commit into
benavlabs:mainfrom
carlosplanchon:fix/lifespan-teardown-masking

Conversation

@carlosplanchon

Copy link
Copy Markdown
Collaborator

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.

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>
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.

1 participant