Skip to content

fix(sqlite): configure busy_timeout on SQLite connections to prevent SQLITE_BUSY lock errors #656

Description

@ZhuchkaTriplesix

Motivation & Problem

In lib/core/database/sqlite_connection.dart (lines 47–53), SQLite databases are opened with PRAGMA foreign_keys = ON;, but without configuring PRAGMA busy_timeout:

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

When an SQLite database file is concurrently accessed by another thread, external process, or background task, transactions and queries immediately fail with DatabaseException(database is locked / SQLITE_BUSY).

Proposed Solution

  1. In SqliteConnection.connect(), configure PRAGMA busy_timeout = 5000; (and PRAGMA foreign_keys = ON;) during database initialization.
  2. Add unit tests verifying that busy_timeout is applied on connection initialization.

Acceptance Criteria

  • SQLite connections execute PRAGMA busy_timeout = 5000; upon connection open.
  • Read-only and read-write SQLite connections handle busy timeouts consistently.
  • Unit tests in test/core/database/ and test/features/sql_workspaces/ pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingerror-handlingTheme parser epic label: error-handlingstabilityTheme 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