From fec258ef129a6fb424d88ae88dc0be390b5f4642 Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Tue, 17 Sep 2024 19:10:55 +0200 Subject: [PATCH] fix: wait for pending transactions before db close This was triggered by some archive decryption test I was writing and possibly also is triggered in production a few times. Waiting for running transactions to complete before closing sounds sensible. --- lib/src/database/indexeddb_box.dart | 3 ++- lib/src/database/sqflite_box.dart | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/database/indexeddb_box.dart b/lib/src/database/indexeddb_box.dart index 9d9b2fd5..98e6df73 100644 --- a/lib/src/database/indexeddb_box.dart +++ b/lib/src/database/indexeddb_box.dart @@ -80,7 +80,8 @@ class BoxCollection with ZoneTransactionMixin { Future close() async { assert(_txnCache == null, 'Database closed while in transaction!'); - return _db.close(); + // Note, zoneTransaction and txnCache are different kinds of transactions. + return zoneTransaction(() async => _db.close()); } @Deprecated('use collection.deleteDatabase now') diff --git a/lib/src/database/sqflite_box.dart b/lib/src/database/sqflite_box.dart index 10da426d..010364ff 100644 --- a/lib/src/database/sqflite_box.dart +++ b/lib/src/database/sqflite_box.dart @@ -66,7 +66,7 @@ class BoxCollection with ZoneTransactionMixin { }, ); - Future close() => _db.close(); + Future close() => zoneTransaction(() => _db.close()); @Deprecated('use collection.deleteDatabase now') static Future delete(String path, [dynamic factory]) =>