Skip to content

Commit 977b2a0

Browse files
cleanup open promise awaits
1 parent cac6202 commit 977b2a0

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,16 @@ export class LockedAsyncDatabaseAdapter
305305
protected async acquireLock(callback: () => Promise<any>, options?: { timeoutMs?: number }): Promise<any> {
306306
await this.waitForInitialized();
307307

308+
// The database is being opened in the background. Wait for it here.
309+
if (this.databaseOpenPromise) {
310+
await this.databaseOpenPromise;
311+
}
312+
308313
return this._acquireLock(async () => {
309314
let holdId: string | null = null;
310315
try {
311-
// The database is being opened in the background. Wait for it here.
316+
// We can't await this since it uses the same lock as we're in now.
312317
if (this.databaseOpenPromise) {
313-
/**
314-
* We can't await this since it uses the same lock as we're in now.
315-
*/
316318
throw new ConnectionClosedError('Connection is busy re-opening');
317319
}
318320

@@ -322,6 +324,7 @@ export class LockedAsyncDatabaseAdapter
322324
if (ex instanceof ConnectionClosedError) {
323325
if (this.options.reOpenOnConnectionClosed && !this.databaseOpenPromise && !this.closing) {
324326
// Immediately re-open the database. We need to miss as little table updates as possible.
327+
// Note, don't await this since it uses the same lock as we're in now.
325328
this.reOpenInternalDB();
326329
}
327330
}

0 commit comments

Comments
 (0)