fix: prevent startup panic when database pool creation fails#3708
Open
tusharmath wants to merge 3 commits into
Open
fix: prevent startup panic when database pool creation fails#3708tusharmath wants to merge 3 commits into
tusharmath wants to merge 3 commits into
Conversation
tusharmath
enabled auto-merge (squash)
July 17, 2026 05:43
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.
Summary
Fix an app crash at startup caused by
DatabasePool::try_from(...).unwrap()when the SQLite database is unavailable (e.g. the file is locked by another process), by deferring pool creation to the first connection request so failures surface as recoverable errors.Changes
TryFrom<PoolConfig>constructor with an infallibleDatabasePool::newthat stores the config and lazily builds the poolget_connectioncall, retrying with exponential backoff and caching the pool on successForgeRepo::newto drop theunwrap()on pool constructionget_connection, and lazy initialization/cachingKey Implementation Details
The pool is now held as
Mutex<Option<DbPool>>: construction never touches the database, and the firstget_connectionbuilds the pool under the lock, reusing the existingretry_with_backofflogic that previously ran eagerly inTryFrom. A poisoned mutex is mapped to an error rather than a panic. The in-memory test constructor pre-populates the pool so its behaviour is unchanged.Testing
Run the new unit tests in
crates/forge_repo/src/database/pool.rs:test_new_with_broken_path_does_not_panic_or_connect,test_get_connection_with_broken_path_returns_error, andtest_get_connection_initializes_pool_lazily. To verify end-to-end, start the app while another process holds a lock on the SQLite file and confirm it no longer panics at startup.