Skip to content

Commit 765209a

Browse files
fix async closing
1 parent 3e7d03e commit 765209a

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

.changeset/loud-mangos-kick.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@powersync/common': patch
3+
'@powersync/web': patch
4+
---
5+
6+
Fixed race condition in async closing of databases

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
515515
}
516516

517517
await this.syncStreamImplementation?.dispose();
518-
this.database.close();
518+
await this.database.close();
519519
this.closed = true;
520520
}
521521

packages/common/src/db/DBAdapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export interface DBLockOptions {
9393
}
9494

9595
export interface DBAdapter extends BaseObserverInterface<DBAdapterListener>, DBGetUtils {
96-
close: () => void;
96+
close: () => void | Promise<void>;
9797
execute: (query: string, params?: any[]) => Promise<QueryResult>;
9898
executeBatch: (query: string, params?: any[][]) => Promise<QueryResult>;
9999
name: string;

packages/web/src/db/adapters/LockedAsyncDatabaseAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ export class LockedAsyncDatabaseAdapter
147147
* Shared workers might not actually close the connection if other
148148
* tabs are still using it.
149149
*/
150-
close() {
150+
async close() {
151151
this._disposeTableChangeListener?.();
152-
this.baseDB?.close?.();
152+
await this.baseDB?.close?.();
153153
}
154154

155155
async getAll<T>(sql: string, parameters?: any[] | undefined): Promise<T[]> {

0 commit comments

Comments
 (0)