From bec5006fe63d7f0238780807a380bdf74bd33de7 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Mon, 2 Jun 2025 22:04:05 +0200 Subject: [PATCH 1/2] Fix a race condition around OPFS databases --- .../lib/src/web/database/web_sqlite_database.dart | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/sqlite_async/lib/src/web/database/web_sqlite_database.dart b/packages/sqlite_async/lib/src/web/database/web_sqlite_database.dart index 0f38b1c..c6d1b75 100644 --- a/packages/sqlite_async/lib/src/web/database/web_sqlite_database.dart +++ b/packages/sqlite_async/lib/src/web/database/web_sqlite_database.dart @@ -8,7 +8,6 @@ import 'package:sqlite_async/src/common/sqlite_database.dart'; import 'package:sqlite_async/src/sqlite_connection.dart'; import 'package:sqlite_async/src/sqlite_options.dart'; import 'package:sqlite_async/src/update_notification.dart'; -import 'package:sqlite_async/src/web/web_mutex.dart'; import 'package:sqlite_async/src/web/web_sqlite_open_factory.dart'; import 'package:sqlite_async/web.dart'; @@ -43,7 +42,6 @@ class SqliteDatabaseImpl @override AbstractDefaultSqliteOpenFactory openFactory; - late final Mutex mutex; late final WebDatabase _connection; StreamSubscription? _broadcastUpdatesSubscription; @@ -77,15 +75,15 @@ class SqliteDatabaseImpl /// 4. Creating temporary views or triggers. SqliteDatabaseImpl.withFactory(this.openFactory, {this.maxReaders = SqliteDatabase.defaultMaxReaders}) { - mutex = MutexImpl(); // This way the `updates` member is available synchronously updates = updatesController.stream; isInitialized = _init(); } Future _init() async { - _connection = await openFactory.openConnection(SqliteOpenOptions( - primaryConnection: true, readOnly: false, mutex: mutex)) as WebDatabase; + _connection = await openFactory.openConnection( + SqliteOpenOptions(primaryConnection: true, readOnly: false)) + as WebDatabase; final broadcastUpdates = _connection.broadcastUpdates; if (broadcastUpdates == null) { From 1ba26159557b3921751d004063dcd426afba819f Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Tue, 3 Jun 2025 10:16:41 +0200 Subject: [PATCH 2/2] Skip lock timeout test --- packages/sqlite_async/test/basic_test.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/sqlite_async/test/basic_test.dart b/packages/sqlite_async/test/basic_test.dart index ed2f708..fb98e17 100644 --- a/packages/sqlite_async/test/basic_test.dart +++ b/packages/sqlite_async/test/basic_test.dart @@ -229,6 +229,10 @@ void main() { ); await completion; + }, onPlatform: { + 'browser': Skip( + 'Web locks are managed with a shared worker, which does not support timeouts', + ) }); }); }