Skip to content

Commit 21cf856

Browse files
Clear retryOps on error (#59)
[Fix] OPFS Potential Deadlocks #56
1 parent 7f9841e commit 21cf856

File tree

8 files changed

+29
-61
lines changed

8 files changed

+29
-61
lines changed

dist/wa-sqlite-async.mjs

Lines changed: 2 additions & 16 deletions
Large diffs are not rendered by default.

dist/wa-sqlite-async.wasm

-18.8 KB
Binary file not shown.

dist/wa-sqlite-jspi.mjs

Lines changed: 2 additions & 16 deletions
Large diffs are not rendered by default.

dist/wa-sqlite-jspi.wasm

-3.12 KB
Binary file not shown.

dist/wa-sqlite.mjs

Lines changed: 2 additions & 16 deletions
Large diffs are not rendered by default.

dist/wa-sqlite.wasm

-3.26 KB
Binary file not shown.

src/examples/OPFSCoopSyncVFS.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,24 @@ export class OPFSCoopSyncVFS extends FacadeVFS {
519519
this._module.retryOps.push((async () => {
520520
// Acquire the Web Lock.
521521
file.persistentFile.handleLockReleaser = await this.#acquireLock(file.persistentFile);
522-
523-
// Get access handles for the database and releated files in parallel.
524-
this.log?.(`creating access handles for ${file.path}`)
525-
await Promise.all(DB_RELATED_FILE_SUFFIXES.map(async suffix => {
526-
const persistentFile = this.persistentFiles.get(file.path + suffix);
527-
if (persistentFile) {
528-
persistentFile.accessHandle =
529-
await persistentFile.fileHandle.createSyncAccessHandle();
530-
}
531-
}));
532-
file.persistentFile.isRequestInProgress = false;
522+
try {
523+
// Get access handles for the database and releated files in parallel.
524+
this.log?.(`creating access handles for ${file.path}`)
525+
await Promise.all(DB_RELATED_FILE_SUFFIXES.map(async suffix => {
526+
const persistentFile = this.persistentFiles.get(file.path + suffix);
527+
if (persistentFile) {
528+
persistentFile.accessHandle =
529+
await persistentFile.fileHandle.createSyncAccessHandle();
530+
}
531+
}));
532+
} catch (e) {
533+
this.log?.(`failed to create access handles for ${file.path}`, e);
534+
// Close any of the potentially opened access handles
535+
this.#releaseAccessHandle(file);
536+
throw e;
537+
} finally {
538+
file.persistentFile.isRequestInProgress = false;
539+
}
533540
})());
534541
return this._module.retryOps.at(-1);
535542
}

src/sqlite-api.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,11 @@ export function Factory(Module) {
873873
// Wait for all pending retry operations to complete. This is
874874
// normally empty on the first loop iteration.
875875
if (Module.retryOps.length) {
876-
await Promise.all(Module.retryOps);
877-
Module.retryOps = [];
876+
try {
877+
await Promise.all(Module.retryOps);
878+
} finally {
879+
Module.retryOps = [];
880+
}
878881
}
879882

880883
rc = await f();

0 commit comments

Comments
 (0)