diff --git a/.changeset/fluffy-plums-carry.md b/.changeset/fluffy-plums-carry.md new file mode 100644 index 00000000..4b1b2161 --- /dev/null +++ b/.changeset/fluffy-plums-carry.md @@ -0,0 +1,5 @@ +--- +'@journeyapps/wa-sqlite': patch +--- + +Fix potential deadlocks and Failed to execute 'createSyncAccessHandle' on 'FileSystemFileHandle' errors. diff --git a/src/examples/OPFSCoopSyncVFS.js b/src/examples/OPFSCoopSyncVFS.js index 90630e6f..33d32cc8 100644 --- a/src/examples/OPFSCoopSyncVFS.js +++ b/src/examples/OPFSCoopSyncVFS.js @@ -519,17 +519,24 @@ 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 + this.#releaseAccessHandle(file); + throw e; + } finally { + file.persistentFile.isRequestInProgress = false; + } })()); return this._module.retryOps.at(-1); }