Skip to content

Commit b5dd523

Browse files
prevent double close
1 parent e261f7e commit b5dd523

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import { mutexRunExclusive } from '../utils/mutex.js';
1818
import { throttleTrailing } from '../utils/throttle.js';
1919
import { SQLOpenFactory, SQLOpenOptions, isDBAdapter, isSQLOpenFactory, isSQLOpenOptions } from './SQLOpenFactory.js';
2020
import { PowerSyncBackendConnector } from './connection/PowerSyncBackendConnector.js';
21+
import { runOnSchemaChange } from './runOnSchemaChange.js';
2122
import { BucketStorageAdapter, PSInternalTable } from './sync/bucket/BucketStorageAdapter.js';
2223
import { CrudBatch } from './sync/bucket/CrudBatch.js';
2324
import { CrudEntry, CrudEntryJSON } from './sync/bucket/CrudEntry.js';
2425
import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
2526
import {
2627
DEFAULT_CRUD_UPLOAD_THROTTLE_MS,
27-
type AdditionalConnectionOptions,
28-
type PowerSyncConnectionOptions,
28+
DEFAULT_RETRY_DELAY_MS,
2929
StreamingSyncImplementation,
3030
StreamingSyncImplementationListener,
31-
DEFAULT_RETRY_DELAY_MS,
31+
type AdditionalConnectionOptions,
32+
type PowerSyncConnectionOptions,
3233
type RequiredAdditionalConnectionOptions
3334
} from './sync/stream/AbstractStreamingSyncImplementation.js';
34-
import { runOnSchemaChange } from './runOnSchemaChange.js';
3535

3636
export interface DisconnectAndClearOptions {
3737
/** When set to false, data in local-only tables is preserved. */
@@ -505,6 +505,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
505505
async close(options: PowerSyncCloseOptions = DEFAULT_POWERSYNC_CLOSE_OPTIONS) {
506506
await this.waitForReady();
507507

508+
if (this.closed) {
509+
return;
510+
}
511+
508512
const { disconnect } = options;
509513
if (disconnect) {
510514
await this.disconnect();

0 commit comments

Comments
 (0)