From 8823c7b0b24990ae72e3d16caba60ab664ccfe9f Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:06:29 -0500 Subject: [PATCH] [PM-8748] Make 5 Seconds the Max we wait for a sync to complete on unlock (#11882) * Make 5 Seconds the Max we wait for a sync to complete on unlock * Move Comment --------- Co-authored-by: Matt Bishop --- .../src/auth/components/lock.component.ts | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/libs/angular/src/auth/components/lock.component.ts b/libs/angular/src/auth/components/lock.component.ts index ce41002985..f28156803c 100644 --- a/libs/angular/src/auth/components/lock.component.ts +++ b/libs/angular/src/auth/components/lock.component.ts @@ -22,6 +22,7 @@ import { MasterPasswordVerification, MasterPasswordVerificationResponse, } from "@bitwarden/common/auth/types/verification"; +import { ClientType } from "@bitwarden/common/enums"; import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; @@ -318,7 +319,24 @@ export class LockComponent implements OnInit, OnDestroy { } // Vault can be de-synced since notifications get ignored while locked. Need to check whether sync is required using the sync service. - await this.syncService.fullSync(false); + const clientType = this.platformUtilsService.getClientType(); + if (clientType === ClientType.Browser || clientType === ClientType.Desktop) { + // Desktop and Browser have better offline support and to facilitate this we don't make the user wait for what + // could be an HTTP Timeout because their server is unreachable. + await Promise.race([ + this.syncService + .fullSync(false) + .catch((err) => this.logService.error("Error during unlock sync", err)), + new Promise((resolve) => + setTimeout(() => { + this.logService.warning("Skipping sync wait, continuing to unlock."); + resolve(); + }, 5_000), + ), + ]); + } else { + await this.syncService.fullSync(false); + } if (this.onSuccessfulSubmit != null) { await this.onSuccessfulSubmit();