diff --git a/native/backup/backup-handler.js b/native/backup/backup-handler.js --- a/native/backup/backup-handler.js +++ b/native/backup/backup-handler.js @@ -130,7 +130,6 @@ if ( !staffCanSee || !canPerformBackupOperation || - backupUploadInProgress.current || deviceKind === 'unknown' ) { return; @@ -144,8 +143,6 @@ } void (async () => { - backupUploadInProgress.current = true; - // CurrentIdentityUserState is required to check if migration to // new flow is needed. let currentIdentityUserState: ?CurrentIdentityUserState = null; @@ -155,7 +152,6 @@ const message = getMessageForException(err) ?? 'unknown error'; showAlertToStaff('Error fetching current device list:', message); console.log('Error fetching current device list:', message); - backupUploadInProgress.current = false; return; } @@ -164,20 +160,29 @@ !currentIdentityUserState.currentDeviceList.curPrimarySignature; if (shouldDoMigration && !socketState.isAuthorized) { - backupUploadInProgress.current = false; return; } - if (shouldDoMigration && deviceKind === 'primary') { - await performMigrationToNewFlow(currentIdentityUserState); - } else if (shouldDoMigration && deviceKind === 'secondary') { - startBackupHandler(); - await performMigrationToNewFlow(currentIdentityUserState); - } else if (deviceKind === 'primary' && !latestBackupInfo) { - await performBackupUpload(); + try { + if (backupUploadInProgress.current) { + return; + } + + backupUploadInProgress.current = true; + + if (shouldDoMigration && deviceKind === 'primary') { + await performMigrationToNewFlow(currentIdentityUserState); + } else if (shouldDoMigration && deviceKind === 'secondary') { + startBackupHandler(); + await performMigrationToNewFlow(currentIdentityUserState); + } else if (deviceKind === 'primary' && !latestBackupInfo) { + await performBackupUpload(); + } + } catch (e) { + console.log(e); + } finally { + backupUploadInProgress.current = false; } - - backupUploadInProgress.current = false; })(); }, [ canPerformBackupOperation,