Fix database lock issue: allow external access after sync finish#4888
Open
meichuanyi wants to merge 1 commit into
Open
Fix database lock issue: allow external access after sync finish#4888meichuanyi wants to merge 1 commit into
meichuanyi wants to merge 1 commit into
Conversation
- Close Collection after sync finish to release database lock - Force WAL checkpoint during sync finish - Set SQLite busy_timeout to 5 seconds for lock contention This fixes the issue where external tools (like REST API) could not access the Anki database after sync operations due to the sync server holding an open connection.
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.
Problem
The sync server holds an open database connection after sync operations complete, preventing external tools (like REST APIs, backup scripts, or monitoring tools) from accessing
collection.anki2.Root causes:
finishhandler only clearssync_statebut doesn't close the Collectionserver_finishdoesn't execute WAL checkpointbusy_timeout=0causes immediate failure on lock contentionSolution
Three minimal changes:
1. Close Collection after finish (
handlers.rs)2. Force WAL checkpoint on finish (
finish.rs)3. Set reasonable busy_timeout (
sqlite.rs)Testing
Impact
busy_timeout=5sprovides graceful handling for brief lock contentionUse Case
This enables scenarios like:
All can now operate without conflicting with sync server's database connection.