Skip to content

Commit

Permalink
ElementR| Retry query backup until it works during migration to avoid…
Browse files Browse the repository at this point in the history
… spurious correption error popup (matrix-org#4113)

* retry query backup until it works during migration

* Add log line when fails to get backup during migration
  • Loading branch information
BillCarsonFr authored Apr 8, 2024
1 parent 0d73d0c commit b352405
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/rust-crypto/libolm_migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -144,6 +146,7 @@ async function migrateBaseData(
legacyStore: CryptoStore,
pickleKey: Uint8Array,
storeHandle: RustSdkCryptoJs.StoreHandle,
logger: Logger,
): Promise<void> {
const migrationData = new RustSdkCryptoJs.BaseMigrationData();
migrationData.userId = new RustSdkCryptoJs.UserId(userId);
Expand All @@ -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;
Expand Down

0 comments on commit b352405

Please sign in to comment.