Skip to content

Commit

Permalink
[PM-16217] Remove wasm timeout (#12476)
Browse files Browse the repository at this point in the history
Remove the WASM timeout logic and supported$.
  • Loading branch information
Hinton authored Dec 20, 2024
1 parent 8c1f1a2 commit 8caadac
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 222 deletions.
18 changes: 0 additions & 18 deletions apps/browser/src/background/main.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,6 @@ export default class MainBackground {
this.accountService,
this.kdfConfigService,
this.keyService,
this.apiService,
);

this.passwordStrengthService = new PasswordStrengthService();
Expand Down Expand Up @@ -1313,23 +1312,6 @@ export default class MainBackground {

await this.initOverlayAndTabsBackground();

if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized
let supported = false;
let error: Error;
try {
supported = await firstValueFrom(this.sdkService.supported$);
} catch (e) {
error = e;
}

if (!supported) {
this.sdkService
.failedToInitialize("background", error)
.catch((e) => this.logService.error(e));
}
}

return new Promise<void>((resolve) => {
setTimeout(async () => {
await this.refreshBadge();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// @ts-strict-ignore
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { SdkClientFactory } from "@bitwarden/common/platform/abstractions/sdk/sdk-client-factory";
import { RecoverableSDKError } from "@bitwarden/common/platform/services/sdk/default-sdk.service";
import type { BitwardenClient } from "@bitwarden/sdk-internal";

import { BrowserApi } from "../../browser/browser-api";
Expand Down Expand Up @@ -72,42 +71,14 @@ export class BrowserSdkClientFactory implements SdkClientFactory {
...args: ConstructorParameters<typeof BitwardenClient>
): Promise<BitwardenClient> {
const startTime = performance.now();
try {
await loadWithTimeout();
} catch (error) {
throw new Error(`Failed to load: ${error.message}`);
}
await load();

const endTime = performance.now();
const elapsed = Math.round((endTime - startTime) / 1000);

const instance = (globalThis as any).init_sdk(...args);

this.logService.info("WASM SDK loaded in", Math.round(endTime - startTime), "ms");

// If it takes 3 seconds or more to load, we want to capture it.
if (elapsed >= 3) {
throw new RecoverableSDKError(instance, elapsed);
}

return instance;
}
}

const loadWithTimeout = async () => {
return new Promise<void>((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error("Operation timed out after 10 second"));
}, 10000);

load()
.then(() => {
clearTimeout(timer);
resolve();
})
.catch((error) => {
clearTimeout(timer);
reject(error);
});
});
};
30 changes: 1 addition & 29 deletions apps/browser/src/popup/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { ChangeDetectorRef, Component, NgZone, OnDestroy, OnInit, inject } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { NavigationEnd, Router, RouterOutlet } from "@angular/router";
import { Subject, takeUntil, firstValueFrom, concatMap, filter, tap } from "rxjs";

Expand All @@ -11,9 +10,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
import { AnimationControlService } from "@bitwarden/common/platform/abstractions/animation-control.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { MessageListener } from "@bitwarden/common/platform/messaging";
import { UserId } from "@bitwarden/common/types/guid";
Expand All @@ -25,7 +22,6 @@ import {
ToastService,
} from "@bitwarden/components";

import { flagEnabled } from "../platform/flags";
import { PopupCompactModeService } from "../platform/popup/layout/popup-compact-mode.service";
import { PopupWidthService } from "../platform/popup/layout/popup-width.service";
import { PopupViewCacheService } from "../platform/popup/view-cache/popup-view-cache.service";
Expand Down Expand Up @@ -72,31 +68,7 @@ export class AppComponent implements OnInit, OnDestroy {
private toastService: ToastService,
private accountService: AccountService,
private animationControlService: AnimationControlService,
private logService: LogService,
private sdkService: SdkService,
) {
if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized
this.sdkService.supported$.pipe(takeUntilDestroyed()).subscribe({
next: (supported) => {
if (!supported) {
this.logService.debug("SDK is not supported");
this.sdkService
.failedToInitialize("popup", undefined)
.catch((e) => this.logService.error(e));
} else {
this.logService.debug("SDK is supported");
}
},
error: (e: unknown) => {
this.sdkService
.failedToInitialize("popup", e as Error)
.catch((e) => this.logService.error(e));
this.logService.error(e);
},
});
}
}
) {}

async ngOnInit() {
initPopupClosedListener();
Expand Down
15 changes: 0 additions & 15 deletions apps/cli/src/service-container/service-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,6 @@ export class ServiceContainer {
this.accountService,
this.kdfConfigService,
this.keyService,
this.apiService,
customUserAgent,
);

Expand Down Expand Up @@ -864,19 +863,5 @@ export class ServiceContainer {
}

this.inited = true;

if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized
let supported = false;
try {
supported = await firstValueFrom(this.sdkService.supported$);
} catch (e) {
// Do nothing.
}

if (!supported) {
this.sdkService.failedToInitialize("cli").catch((e) => this.logService.error(e));
}
}
}
}
37 changes: 2 additions & 35 deletions apps/desktop/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,8 @@ import {
ViewChild,
ViewContainerRef,
} from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { Router } from "@angular/router";
import {
catchError,
filter,
firstValueFrom,
map,
of,
Subject,
takeUntil,
timeout,
withLatestFrom,
} from "rxjs";
import { filter, firstValueFrom, map, Subject, takeUntil, timeout, withLatestFrom } from "rxjs";

import { CollectionService } from "@bitwarden/admin-console/common";
import { ModalRef } from "@bitwarden/angular/components/modal/modal.ref";
Expand Down Expand Up @@ -52,7 +41,6 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { SystemService } from "@bitwarden/common/platform/abstractions/system.service";
import { clearCaches } from "@bitwarden/common/platform/misc/sequentialize";
Expand All @@ -70,7 +58,6 @@ import { KeyService, BiometricStateService } from "@bitwarden/key-management";

import { DeleteAccountComponent } from "../auth/delete-account.component";
import { MenuAccount, MenuUpdateRequest } from "../main/menu/menu.updater";
import { flagEnabled } from "../platform/flags";
import { PremiumComponent } from "../vault/app/accounts/premium.component";
import { FolderAddEditComponent } from "../vault/app/vault/folder-add-edit.component";

Expand Down Expand Up @@ -167,28 +154,8 @@ export class AppComponent implements OnInit, OnDestroy {
private biometricStateService: BiometricStateService,
private stateEventRunnerService: StateEventRunnerService,
private accountService: AccountService,
private sdkService: SdkService,
private organizationService: OrganizationService,
) {
if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized
this.sdkService.supported$
.pipe(
takeUntilDestroyed(),
catchError(() => {
return of(false);
}),
)
.subscribe((supported) => {
if (!supported) {
this.logService.debug("SDK is not supported");
this.sdkService.failedToInitialize("desktop").catch((e) => this.logService.error(e));
} else {
this.logService.debug("SDK is supported");
}
});
}
}
) {}

ngOnInit() {
this.accountService.activeAccount$.pipe(takeUntil(this.destroy$)).subscribe((account) => {
Expand Down
30 changes: 2 additions & 28 deletions apps/web/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// @ts-strict-ignore
import { DOCUMENT } from "@angular/common";
import { Component, Inject, NgZone, OnDestroy, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { NavigationEnd, Router } from "@angular/router";
import * as jq from "jquery";
import { Subject, filter, firstValueFrom, map, takeUntil, timeout, catchError, of } from "rxjs";
import { Subject, filter, firstValueFrom, map, takeUntil, timeout } from "rxjs";

import { CollectionService } from "@bitwarden/admin-console/common";
import { EventUploadService } from "@bitwarden/common/abstractions/event/event-upload.service";
Expand All @@ -22,9 +21,7 @@ import { ProcessReloadServiceAbstraction } from "@bitwarden/common/key-managemen
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { StateEventRunnerService } from "@bitwarden/common/platform/state";
import { SyncService } from "@bitwarden/common/platform/sync";
Expand All @@ -34,8 +31,6 @@ import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { KeyService, BiometricStateService } from "@bitwarden/key-management";

import { flagEnabled } from "../utils/flags";

import { PolicyListService } from "./admin-console/core/policy-list.service";
import {
DisableSendPolicy,
Expand Down Expand Up @@ -93,29 +88,8 @@ export class AppComponent implements OnDestroy, OnInit {
private stateEventRunnerService: StateEventRunnerService,
private organizationService: InternalOrganizationServiceAbstraction,
private accountService: AccountService,
private logService: LogService,
private sdkService: SdkService,
private processReloadService: ProcessReloadServiceAbstraction,
) {
if (flagEnabled("sdk")) {
// Warn if the SDK for some reason can't be initialized
this.sdkService.supported$
.pipe(
takeUntilDestroyed(),
catchError(() => {
return of(false);
}),
)
.subscribe((supported) => {
if (!supported) {
this.logService.debug("SDK is not supported");
this.sdkService.failedToInitialize("web").catch((e) => this.logService.error(e));
} else {
this.logService.debug("SDK is supported");
}
});
}
}
) {}

ngOnInit() {
this.i18nService.locale$.pipe(takeUntil(this.destroy$)).subscribe((locale) => {
Expand Down
1 change: 0 additions & 1 deletion libs/angular/src/services/jslib-services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,6 @@ const safeProviders: SafeProvider[] = [
AccountServiceAbstraction,
KdfConfigService,
KeyServiceAbstraction,
ApiServiceAbstraction,
],
}),
safeProvider({
Expand Down
7 changes: 0 additions & 7 deletions libs/common/src/platform/abstractions/sdk/sdk.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { BitwardenClient } from "@bitwarden/sdk-internal";
import { UserId } from "../../../types/guid";

export abstract class SdkService {
/**
* Check if the SDK is supported in the current environment.
*/
supported$: Observable<boolean>;

/**
* Retrieve the version of the SDK.
*/
Expand All @@ -35,6 +30,4 @@ export abstract class SdkService {
* @param userId
*/
abstract userClient$(userId: UserId): Observable<BitwardenClient>;

abstract failedToInitialize(category: string, error?: Error): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BehaviorSubject, firstValueFrom, of } from "rxjs";
import { KdfConfigService, KeyService, PBKDF2KdfConfig } from "@bitwarden/key-management";
import { BitwardenClient } from "@bitwarden/sdk-internal";

import { ApiService } from "../../../abstractions/api.service";
import { AccountInfo, AccountService } from "../../../auth/abstractions/account.service";
import { UserId } from "../../../types/guid";
import { UserKey } from "../../../types/key";
Expand All @@ -24,7 +23,6 @@ describe("DefaultSdkService", () => {
let accountService!: MockProxy<AccountService>;
let kdfConfigService!: MockProxy<KdfConfigService>;
let keyService!: MockProxy<KeyService>;
let apiService!: MockProxy<ApiService>;
let service!: DefaultSdkService;

let mockClient!: MockProxy<BitwardenClient>;
Expand All @@ -36,7 +34,6 @@ describe("DefaultSdkService", () => {
accountService = mock<AccountService>();
kdfConfigService = mock<KdfConfigService>();
keyService = mock<KeyService>();
apiService = mock<ApiService>();

// Can't use `of(mock<Environment>())` for some reason
environmentService.environment$ = new BehaviorSubject(mock<Environment>());
Expand All @@ -48,7 +45,6 @@ describe("DefaultSdkService", () => {
accountService,
kdfConfigService,
keyService,
apiService,
);

mockClient = mock<BitwardenClient>();
Expand Down
Loading

0 comments on commit 8caadac

Please sign in to comment.