diff --git a/indexedDb/init.go b/indexedDb/init.go index 22ea3319981f8c59c58d0d1cae0b113eefb193a3..d6d9d673d0fc9f586d7be5a95f3cfa8d740958b7 100644 --- a/indexedDb/init.go +++ b/indexedDb/init.go @@ -93,6 +93,27 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher, return nil, err } + // FIXME: The below is a hack that for some reason prevents moving on with + // uninitialized database despite the previous call to Await. + // It would be idea to find a different solution. + // Close and open again to ensure the state is finalized + err = db.Close() + if err != nil { + return nil, err + } + openRequest, err = idb.Global().Open(ctx, databaseName, currentVersion, + func(db *idb.Database, oldVersion, newVersion uint) error { + return nil + }) + if err != nil { + return nil, err + } + // Wait for database open to finish + db, err = openRequest.Await(ctx) + if err != nil { + return nil, err + } + // Save the encryption status to storage encryptionStatus := encryption != nil loadedEncryptionStatus, err := storage.StoreIndexedDbEncryptionStatus( @@ -111,7 +132,7 @@ func newWASMModel(databaseName string, encryption cryptoChannel.Cipher, // Attempt to ensure the database has been properly initialized wrapper := &wasmModel{db: db, receivedMessageCB: cb, cipher: encryption} - return wrapper, wrapper.hackTestDb() + return wrapper, nil } // v1Upgrade performs the v0 -> v1 database upgrade.