Skip to content

Commit 83b82c9

Browse files
authored
Merge pull request #272 from powersync-ja/fix-connect-on-open
Fix deadlock on immediate connect call
2 parents d560134 + dd58bbf commit 83b82c9

File tree

26 files changed

+107
-28
lines changed

26 files changed

+107
-28
lines changed

CHANGELOG.md

+32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,38 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## 2025-04-24
7+
8+
### Changes
9+
10+
---
11+
12+
Packages with breaking changes:
13+
14+
- There are no breaking changes in this release.
15+
16+
Packages with other changes:
17+
18+
- [`powersync_core` - `v1.2.4`](#powersync_core---v124)
19+
- [`powersync_attachments_helper` - `v0.6.18+6`](#powersync_attachments_helper---v06186)
20+
- [`powersync_sqlcipher` - `v0.1.5+4`](#powersync_sqlcipher---v0154)
21+
- [`powersync` - `v1.12.4`](#powersync---v1124)
22+
23+
Packages with dependency updates only:
24+
25+
> Packages listed below depend on other packages in this workspace that have had changes. Their versions have been incremented to bump the minimum dependency versions of the packages they depend upon in this project.
26+
27+
- `powersync_attachments_helper` - `v0.6.18+6`
28+
- `powersync_sqlcipher` - `v0.1.5+4`
29+
- `powersync` - `v1.12.4`
30+
31+
---
32+
33+
#### `powersync_core` - `v1.2.4`
34+
35+
- Fix deadlock when `connect()` is called immediately after opening a database.
36+
37+
638
## 2025-04-22
739

840
### Changes

demos/benchmarks/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
powersync: ^1.12.3
13+
powersync: ^1.12.4
1414
path_provider: ^2.1.1
1515
path: ^1.8.3
1616
logging: ^1.2.0

demos/django-todolist/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
powersync: ^1.12.3
13+
powersync: ^1.12.4
1414
path_provider: ^2.1.1
1515
path: ^1.8.3
1616
logging: ^1.2.0

demos/firebase-nodejs-todolist/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313

14-
powersync: ^1.12.3
14+
powersync: ^1.12.4
1515
path_provider: ^2.1.1
1616
supabase_flutter: ^2.0.1
1717
path: ^1.8.3

demos/supabase-anonymous-auth/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313

14-
powersync: ^1.12.3
14+
powersync: ^1.12.4
1515
path_provider: ^2.1.1
1616
supabase_flutter: ^2.0.2
1717
path: ^1.8.3

demos/supabase-edge-function-auth/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ dependencies:
1111
flutter:
1212
sdk: flutter
1313

14-
powersync: ^1.12.3
14+
powersync: ^1.12.4
1515
path_provider: ^2.1.1
1616
supabase_flutter: ^2.0.2
1717
path: ^1.8.3

demos/supabase-simple-chat/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies:
3737

3838
supabase_flutter: ^2.0.2
3939
timeago: ^3.6.0
40-
powersync: ^1.12.3
40+
powersync: ^1.12.4
4141
path_provider: ^2.1.1
4242
path: ^1.8.3
4343
logging: ^1.2.0

demos/supabase-todolist-drift/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ environment:
99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
powersync_attachments_helper: ^0.6.18+5
13-
powersync: ^1.12.3
12+
powersync_attachments_helper: ^0.6.18+6
13+
powersync: ^1.12.4
1414
path_provider: ^2.1.1
1515
supabase_flutter: ^2.0.1
1616
path: ^1.8.3

demos/supabase-todolist-optional-sync/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
powersync: ^1.12.3
13+
powersync: ^1.12.4
1414
path_provider: ^2.1.1
1515
supabase_flutter: ^2.0.1
1616
path: ^1.8.3

demos/supabase-todolist/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
powersync_attachments_helper: ^0.6.18+5
14-
powersync: ^1.12.3
13+
powersync_attachments_helper: ^0.6.18+6
14+
powersync: ^1.12.4
1515
path_provider: ^2.1.1
1616
supabase_flutter: ^2.0.1
1717
path: ^1.8.3

demos/supabase-trello/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies:
3636
random_name_generator: ^1.5.0
3737
flutter_dotenv: ^5.2.1
3838
logging: ^1.3.0
39-
powersync: ^1.12.3
39+
powersync: ^1.12.4
4040
sqlite_async: ^0.11.0
4141
path_provider: ^2.1.5
4242
supabase_flutter: ^2.8.3

packages/powersync/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.12.4
2+
3+
- Update a dependency to the latest release.
4+
15
## 1.12.3
26

37
This updates `powersync_core` to version `1.2.3`, which includes these changes:

packages/powersync/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: powersync
2-
version: 1.12.3
2+
version: 1.12.4
33
homepage: https://powersync.com
44
repository: https://github.com/powersync-ja/powersync.dart
55
description: PowerSync Flutter SDK. Sync Postgres, MongoDB or MySQL with SQLite in your Flutter app
@@ -12,7 +12,7 @@ dependencies:
1212
sdk: flutter
1313

1414
sqlite3_flutter_libs: ^0.5.23
15-
powersync_core: ^1.2.3
15+
powersync_core: ^1.2.4
1616
powersync_flutter_libs: ^0.4.7
1717
collection: ^1.17.0
1818

packages/powersync_attachments_helper/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.6.18+6
2+
3+
- Update a dependency to the latest release.
4+
15
## 0.6.18+5
26

37
- Update a dependency to the latest release.

packages/powersync_attachments_helper/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: powersync_attachments_helper
22
description: A helper library for handling attachments when using PowerSync.
3-
version: 0.6.18+5
3+
version: 0.6.18+6
44
repository: https://github.com/powersync-ja/powersync.dart
55
homepage: https://www.powersync.com/
66
environment:
@@ -10,7 +10,7 @@ dependencies:
1010
flutter:
1111
sdk: flutter
1212

13-
powersync_core: ^1.2.3
13+
powersync_core: ^1.2.4
1414
logging: ^1.2.0
1515
sqlite_async: ^0.11.0
1616
path_provider: ^2.0.13

packages/powersync_core/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.4
2+
3+
- Fix deadlock when `connect()` is called immediately after opening a database.
4+
15
## 1.2.3
26

37
- Introduce locks to avoid duplicate sync streams when multiple instances of the same database are opened.

packages/powersync_core/lib/src/database/native/native_powersync_database.dart

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class PowerSyncDatabaseImpl
122122
required AbortController abort,
123123
Map<String, dynamic>? params,
124124
}) async {
125-
await initialize();
126125
final dbRef = database.isolateConnectionFactory();
127126

128127
bool triedSpawningIsolate = false;

packages/powersync_core/lib/src/database/powersync_db_mixin.dart

+5
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ mixin PowerSyncDatabaseMixin implements SqliteConnection {
264264
Duration crudThrottleTime = const Duration(milliseconds: 10),
265265
Map<String, dynamic>? params,
266266
}) async {
267+
// The initialization process acquires a sync connect lock (through
268+
// updateSchema), so ensure the database is ready before we try to acquire
269+
// the lock for the connection.
270+
await initialize();
271+
267272
clientParams = params;
268273
var thisConnectAborter = AbortController();
269274

packages/powersync_core/lib/src/database/web/web_powersync_database.dart

-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ class PowerSyncDatabaseImpl
118118
required AbortController abort,
119119
Map<String, dynamic>? params,
120120
}) async {
121-
await initialize();
122-
123121
final crudStream =
124122
database.onChange(['ps_crud'], throttle: crudThrottleTime);
125123

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const String libraryVersion = '1.2.3';
1+
const String libraryVersion = '1.2.4';

packages/powersync_core/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: powersync_core
2-
version: 1.2.3
2+
version: 1.2.4
33
homepage: https://powersync.com
44
repository: https://github.com/powersync-ja/powersync.dart
55
description: PowerSync Dart SDK - sync engine for building local-first apps.

packages/powersync_core/test/streaming_sync_test.dart

+19
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ void main() {
6161
server.close();
6262
});
6363

64+
test('can connect as initial operation', () async {
65+
final server = await createServer();
66+
final ignoreLogger = Logger.detached('powersync.test');
67+
68+
final pdb = await testUtils.setupPowerSync(
69+
path: path, logger: ignoreLogger, initialize: false);
70+
pdb.retryDelay = Duration(milliseconds: 5000);
71+
72+
await pdb.connect(connector: TestConnector(() async {
73+
return PowerSyncCredentials(endpoint: server.endpoint, token: 'token');
74+
}));
75+
76+
await expectLater(
77+
pdb.statusStream,
78+
emitsThrough(
79+
isA<SyncStatus>().having((e) => e.connected, 'connected', isTrue)),
80+
);
81+
});
82+
6483
test('full powersync reconnect', () async {
6584
// Test repeatedly creating new PowerSync connections, then disconnect
6685
// and close the connection.

packages/powersync_core/test/utils/abstract_test_utils.dart

+9-3
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,18 @@ abstract class AbstractTestUtils {
9494
SqliteOptions options = const SqliteOptions.defaults()});
9595

9696
/// Creates a SqliteDatabaseConnection
97-
Future<PowerSyncDatabase> setupPowerSync(
98-
{String? path, Schema? schema, Logger? logger}) async {
97+
Future<PowerSyncDatabase> setupPowerSync({
98+
String? path,
99+
Schema? schema,
100+
Logger? logger,
101+
bool initialize = true,
102+
}) async {
99103
final db = PowerSyncDatabase.withFactory(await testFactory(path: path),
100104
schema: schema ?? defaultSchema,
101105
logger: logger ?? _makeTestLogger(name: _testName));
102-
await db.initialize();
106+
if (initialize) {
107+
await db.initialize();
108+
}
103109
addTearDown(db.close);
104110
return db;
105111
}

packages/powersync_core/test/utils/web_test_utils.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,13 @@ class TestUtils extends AbstractTestUtils {
7676

7777
@override
7878
Future<PowerSyncDatabase> setupPowerSync(
79-
{String? path, Schema? schema, Logger? logger}) async {
79+
{String? path,
80+
Schema? schema,
81+
Logger? logger,
82+
bool initialize = true}) async {
8083
await _isInitialized;
81-
return super.setupPowerSync(path: path, schema: schema, logger: logger);
84+
return super.setupPowerSync(
85+
path: path, schema: schema, logger: logger, initialize: initialize);
8286
}
8387

8488
@override

packages/powersync_sqlcipher/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.5+4
2+
3+
- Update a dependency to the latest release.
4+
15
## 0.1.5+3
26

37
This updates `powersync_core` to version `1.2.3`, which includes these changes:

packages/powersync_sqlcipher/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: powersync_sqlcipher
2-
version: 0.1.5+3
2+
version: 0.1.5+4
33
homepage: https://powersync.com
44
repository: https://github.com/powersync-ja/powersync.dart
55
description: PowerSync Flutter SDK - sync engine for building local-first apps.
@@ -12,7 +12,7 @@ dependencies:
1212
flutter:
1313
sdk: flutter
1414

15-
powersync_core: ^1.2.3
15+
powersync_core: ^1.2.4
1616
powersync_flutter_libs: ^0.4.7
1717
sqlcipher_flutter_libs: ^0.6.4
1818
sqlite3_web: ^0.3.0

0 commit comments

Comments
 (0)