Skip to content

Commit 82eb502

Browse files
[Fix] OPFS Potential Deadlocks (#56)
* fix access handle deadlock * set the releaser to null for good measure * cleanup. call releaseAccessHandle on error
1 parent 9598189 commit 82eb502

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

.changeset/fluffy-plums-carry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/wa-sqlite': patch
3+
---
4+
5+
Fix potential deadlocks and Failed to execute 'createSyncAccessHandle' on 'FileSystemFileHandle' errors.

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
}

0 commit comments

Comments
 (0)