Skip to content

fix(storage): enable WAL mode and busy_timeout in LocalDb for concurrent lock resilience #611

Description

@ZhuchkaTriplesix

Problem

In lib/core/storage/local_db.dart, the local SQLite database (querya.db) initialization only executes PRAGMA foreign_keys = ON in onOpen:

onOpen: (db) async {
  await db.execute('PRAGMA foreign_keys = ON');
}

By default, SQLite uses journal_mode = DELETE with a busy_timeout of 0 ms. When concurrent operations occur (e.g. background query history recording, cloud sync folder watchers, or multiple rapid app reads/writes), SQLite immediately fails with DatabaseException: SQLITE_BUSY (database is locked).

Proposed Solution

  1. In LocalDb._open() (onOpen callback), configure robust concurrent PRAGMAs:
    • PRAGMA journal_mode = WAL; (Write-Ahead Logging allows non-blocking concurrent readers while a write occurs).
    • PRAGMA busy_timeout = 5000; (Gracefully retry for up to 5000ms instead of immediately failing).
    • PRAGMA synchronous = NORMAL; (Optimal and safe synchronization mode under WAL).
  2. Add unit tests in test/core/storage/local_db_test.dart verifying that PRAGMA settings are active and concurrent reads/writes succeed without locking errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    stabilityTheme parser epic label: stabilitystorageTheme parser epic label: storage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions