diff --git a/src/rust-crypto/libolm_migration.ts b/src/rust-crypto/libolm_migration.ts index b8e617e182f..1d4179601b6 100644 --- a/src/rust-crypto/libolm_migration.ts +++ b/src/rust-crypto/libolm_migration.ts @@ -25,6 +25,8 @@ import { requestKeyBackupVersion } from "./backup"; import { IRoomEncryption } from "../crypto/RoomList"; import { CrossSigningKeyInfo } from "../crypto-api"; import { RustCrypto } from "./rust-crypto"; +import { KeyBackupInfo } from "../crypto-api/keybackup"; +import { sleep } from "../utils"; /** * Determine if any data needs migrating from the legacy store, and do so. @@ -105,7 +107,7 @@ export async function migrateFromLegacyCrypto(args: { if (migrationState === MigrationState.NOT_STARTED) { logger.info("Migrating data from legacy crypto store. Step 1: base data"); - await migrateBaseData(args.http, args.userId, args.deviceId, legacyStore, pickleKey, args.storeHandle); + await migrateBaseData(args.http, args.userId, args.deviceId, legacyStore, pickleKey, args.storeHandle, logger); migrationState = MigrationState.INITIAL_DATA_MIGRATED; await legacyStore.setMigrationState(migrationState); @@ -144,6 +146,7 @@ async function migrateBaseData( legacyStore: CryptoStore, pickleKey: Uint8Array, storeHandle: RustSdkCryptoJs.StoreHandle, + logger: Logger, ): Promise { const migrationData = new RustSdkCryptoJs.BaseMigrationData(); migrationData.userId = new RustSdkCryptoJs.UserId(userId); @@ -160,7 +163,18 @@ async function migrateBaseData( // If we have a backup recovery key, we need to try to figure out which backup version it is for. // All we can really do is ask the server for the most recent version. if (recoveryKey) { - const backupInfo = await requestKeyBackupVersion(http); + let backupCallDone = false; + let backupInfo: KeyBackupInfo | null = null; + while (!backupCallDone) { + try { + backupInfo = await requestKeyBackupVersion(http); + backupCallDone = true; + } catch (e) { + logger.info("Failed to get backup version during migration, retrying in 2 seconds", e); + // Retry until successful, use simple constant delay + await sleep(2000); + } + } if (backupInfo) { migrationData.backupVersion = backupInfo.version; migrationData.backupRecoveryKey = recoveryKey;