Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-plums-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@journeyapps/wa-sqlite': patch
---

Fix potential deadlocks and Failed to execute 'createSyncAccessHandle' on 'FileSystemFileHandle' errors.
37 changes: 26 additions & 11 deletions src/examples/OPFSCoopSyncVFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,17 +519,32 @@ export class OPFSCoopSyncVFS extends FacadeVFS {
this._module.retryOps.push((async () => {
// Acquire the Web Lock.
file.persistentFile.handleLockReleaser = await this.#acquireLock(file.persistentFile);

// Get access handles for the database and releated files in parallel.
this.log?.(`creating access handles for ${file.path}`)
await Promise.all(DB_RELATED_FILE_SUFFIXES.map(async suffix => {
const persistentFile = this.persistentFiles.get(file.path + suffix);
if (persistentFile) {
persistentFile.accessHandle =
await persistentFile.fileHandle.createSyncAccessHandle();
}
}));
file.persistentFile.isRequestInProgress = false;
try {
// Get access handles for the database and releated files in parallel.
this.log?.(`creating access handles for ${file.path}`)
await Promise.all(DB_RELATED_FILE_SUFFIXES.map(async suffix => {
const persistentFile = this.persistentFiles.get(file.path + suffix);
if (persistentFile) {
persistentFile.accessHandle =
await persistentFile.fileHandle.createSyncAccessHandle();
}
}));
} catch (e) {
this.log?.(`failed to create access handles for ${file.path}`, e);
// Close any of the potentially opened access handles
DB_RELATED_FILE_SUFFIXES.forEach(async suffix => {
const persistentFile = this.persistentFiles.get(file.path + suffix);
if (persistentFile) {
persistentFile.accessHandle?.close();
}
});
// Release the lock, if we failed here, we'd need to obtain the lock later in order to retry
file.persistentFile.handleLockReleaser();
file.persistentFile.handleLockReleaser = null;
throw e;
} finally {
file.persistentFile.isRequestInProgress = false;
}
})());
return this._module.retryOps.at(-1);
}
Expand Down