mirror of https://github.com/AMT-Cheif/drift.git
Fix race condition in database opening
This commit is contained in:
parent
1bbc26767e
commit
3c56e0ad6e
|
@ -159,7 +159,7 @@ packages:
|
|||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.7"
|
||||
version: "1.1.6"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -173,14 +173,14 @@ packages:
|
|||
path: "../../../moor"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.6.0"
|
||||
version: "1.7.1"
|
||||
moor_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../../../moor_flutter"
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.6.0"
|
||||
version: "1.7.0"
|
||||
multi_server_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -232,6 +232,8 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate {
|
|||
@override
|
||||
SqlDialect get dialect => delegate.dialect;
|
||||
|
||||
final Lock _openingLock = Lock();
|
||||
|
||||
DelegatedDatabase(this.delegate,
|
||||
{this.logStatements, this.isSequential = false}) {
|
||||
// not using default value because it's commonly set to null
|
||||
|
@ -240,7 +242,7 @@ class DelegatedDatabase extends QueryExecutor with _ExecutorWithQueryDelegate {
|
|||
|
||||
@override
|
||||
Future<bool> ensureOpen() {
|
||||
return _synchronized(() async {
|
||||
return _openingLock.synchronized(() async {
|
||||
final alreadyOpen = await delegate.isOpen;
|
||||
if (alreadyOpen) return true;
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ class _SqfliteDelegate extends DatabaseDelegate with _SqfliteExecutor {
|
|||
|
||||
@override
|
||||
Future<void> open([GeneratedDatabase db]) async {
|
||||
print('uses fix for the opening problem.');
|
||||
assert(
|
||||
!_debugIsOpening && !isOpen,
|
||||
'Database opened multiple times, this should never happen. '
|
||||
|
|
Loading…
Reference in New Issue