From 37d2ea63151b87d8e60b57f3c5889450e10345d8 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 30 Aug 2026 17:49:36 +0300 Subject: [PATCH] fix(sqlite): configure busy_timeout on SQLite connections - Configure PRAGMA busy_timeout = 5000 in SqliteConnection.connect() onOpen - Prevent immediate SQLITE_BUSY / database locked errors during concurrent disk access - Add unit test verifying PRAGMA busy_timeout on connection initialization Closes #656 --- lib/core/database/sqlite_connection.dart | 1 + test/core/database/sqlite_connection_test.dart | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/core/database/sqlite_connection.dart b/lib/core/database/sqlite_connection.dart index c699fa2b..153bdf98 100644 --- a/lib/core/database/sqlite_connection.dart +++ b/lib/core/database/sqlite_connection.dart @@ -45,6 +45,7 @@ class SqliteConnection { options: OpenDatabaseOptions( readOnly: readOnly, onOpen: (db) async { + await db.execute('PRAGMA busy_timeout = 5000'); if (!readOnly) { await db.execute('PRAGMA foreign_keys = ON'); } diff --git a/test/core/database/sqlite_connection_test.dart b/test/core/database/sqlite_connection_test.dart index cd2612f9..d00cfbe9 100644 --- a/test/core/database/sqlite_connection_test.dart +++ b/test/core/database/sqlite_connection_test.dart @@ -69,6 +69,13 @@ void main() { expect(conn.isConnected, false); }); + test('configures PRAGMA busy_timeout to 5000 on connection open', () async { + await conn.connect(); + final res = await conn.execute('PRAGMA busy_timeout'); + expect(res, isNotEmpty); + expect(res.first['timeout'], 5000); + }); + test('testConnection connects, queries and cleans up', () async { final ok = await conn.testConnection(); expect(ok, true);