Fix: Resolve DuckDB lock conflicts between CLI commands and running application#29
Merged
mahesh-solanke merged 3 commits intoJan 11, 2026
Conversation
- Introduced a new `parse_lock_error` function to extract process information from DuckDB lock error messages, improving error handling during database operations. - Updated the `init` function to support resetting the database via an HTTP API if the application is running, enhancing user experience and flexibility. - Improved error messages for locked databases, providing clearer guidance on resolving lock issues. - Refactored the `DevTrackDB` class to support read-only and write modes, allowing for better control over database access. - Updated various commands and middleware to utilize the new read/write capabilities, ensuring consistent behavior across the application.
…dling - Added a new function `check_db_initialized_via_api` to verify if the database is initialized through the HTTP API, providing users with real-time feedback on database status. - Updated the `init` function to utilize the new API check before prompting for database overwrite, improving user experience when the application is running. - Enhanced error handling in the `query` and `stat` functions to attempt fetching logs and stats via the HTTP endpoint if the database is locked, ensuring better resilience and user guidance. - Improved console output messages to inform users about the database state and actions they can take, such as resetting the database.
…lock error handling - Added a pytest fixture to automatically mock network requests, preventing hangs during CI and allowing tests to override specific behaviors as needed. - Updated the `test_init_locked_database` function to provide clearer error messages for locked databases and ensure graceful handling of lock scenarios during initialization. - Improved the mocking of database initialization errors to include process information for better debugging.
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.
Fix: Resolve DuckDB lock conflicts between CLI commands and running application
Problem
CLI commands (
stat,query,init) fail when the database is locked by a running application due to DuckDB's file-level locking mechanism.Solution
stat,query, andinitcommands when database lock is detectedinitcommand now checks database status via API before prompting for overwrite--forceflag to properly exit after successful API resetChanges
cli.py: Added API fallback logic withcheck_db_initialized_via_api()helperdatabase.py: Improved connection handling for read/write mode transitionsTesting
All CLI commands tested with running application to verify graceful fallback behavior.