@@ -519,17 +519,31 @@ 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+ DB_RELATED_FILE_SUFFIXES . forEach ( async suffix => {
536+ const persistentFile = this . persistentFiles . get ( file . path + suffix ) ;
537+ if ( persistentFile ) {
538+ persistentFile . accessHandle ?. close ( ) ;
539+ }
540+ } ) ;
541+ // Release the lock, if we failed here, we'd need to obtain the lock later in order to retry
542+ file . persistentFile . handleLockReleaser ( ) ;
543+ throw e ;
544+ } finally {
545+ file . persistentFile . isRequestInProgress = false ;
546+ }
533547 } ) ( ) ) ;
534548 return this . _module . retryOps . at ( - 1 ) ;
535549 }
0 commit comments