Skip to content

Commit

Permalink
[PM-8748] Make 5 Seconds the Max we wait for a sync to complete on un…
Browse files Browse the repository at this point in the history
…lock (#11882)

* Make 5 Seconds the Max we wait for a sync to complete on unlock

* Move Comment

---------

Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
  • Loading branch information
justindbaur and withinfocus authored Nov 19, 2024
1 parent ce042d4 commit 8823c7b
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion libs/angular/src/auth/components/lock.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<void>((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();
Expand Down

0 comments on commit 8823c7b

Please sign in to comment.