Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/powersync/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 2.3.3

- Restore the ability to call `disconnect()` on closed databases.
- Internal: Update PowerSync SQLite core extension to latest version.

## 2.3.2
Expand Down
4 changes: 3 additions & 1 deletion packages/powersync/lib/src/database/powersync_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ abstract base class PowerSyncDatabase extends SqliteConnection {
///
/// Use [connect] to connect again.
Future<void> disconnect() async {
await _connections.disconnect();
if (!database.closed) {
await _connections.disconnect();
}
}

/// Disconnect and clear the database.
Expand Down
11 changes: 11 additions & 0 deletions packages/powersync/test/sync/in_memory_sync_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -988,5 +988,16 @@ void _declareTests(String name, SyncOptions options, bool bson) {
expect(database.currentStatus.anyError, isNull);
});
});

test('can call disconnect on closed database', () async {
// Regression test for https://github.com/powersync-ja/powersync.dart/issues/448,
// calling disconnect() on a closed database should be a harmless no-op.
final status = await waitForConnection();
await database.close();
await expectLater(status, emitsThrough(isSyncStatus(connected: false)));
await expectLater(status, emitsDone);

await database.disconnect();
});
});
}