1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-14 02:08:50 +02:00

Fix/lock lowdb file (#470)

* Lock data.json while running

* Await floating promises

* Increase retry frequency and attempt count for lock file

* tweak lock retry times
This commit is contained in:
Matt Gibson 2022-02-10 10:24:41 -06:00 committed by GitHub
parent 2ae2fdfd14
commit ee664059d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 115 additions and 1565 deletions

1627
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -65,6 +65,8 @@
"@types/node-fetch": "^2.5.10",
"@types/node-forge": "^0.9.7",
"@types/papaparse": "^5.2.5",
"@types/proper-lockfile": "^4.1.2",
"@types/retry": "^0.12.1",
"@types/tldjs": "^2.3.0",
"@types/zxcvbn": "^4.4.1",
"clean-webpack-plugin": "^4.0.0",
@ -107,6 +109,7 @@
"node-forge": "0.10.0",
"open": "^8.0.8",
"papaparse": "^5.3.0",
"proper-lockfile": "^4.1.2",
"rxjs": "6.6.7",
"tldjs": "^2.3.1",
"zxcvbn": "^4.4.2"

View File

@ -10,6 +10,7 @@ import { LogLevelType } from "jslib-common/enums/logLevelType";
import { AuthService } from "jslib-common/services/auth.service";
import { I18nService } from "./services/i18n.service";
import { LowdbStorageService } from "./services/lowdbStorage.service";
import { NodeEnvSecureStorageService } from "./services/nodeEnvSecureStorage.service";
import { CliPlatformUtilsService } from "jslib-node/cli/services/cliPlatformUtils.service";
@ -44,7 +45,6 @@ import { TwoFactorService } from "jslib-common/services/twoFactor.service";
import { UserVerificationService } from "jslib-common/services/userVerification.service";
import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
import { LowdbStorageService } from "jslib-node/services/lowdbStorage.service";
import { NodeApiService } from "jslib-node/services/nodeApi.service";
import { NodeCryptoFunctionService } from "jslib-node/services/nodeCryptoFunction.service";
@ -129,7 +129,7 @@ export class Main {
(level) => process.env.BITWARDENCLI_DEBUG !== "true" && level <= LogLevelType.Info
);
this.cryptoFunctionService = new NodeCryptoFunctionService();
this.storageService = new LowdbStorageService(this.logService, null, p, false);
this.storageService = new LowdbStorageService(this.logService, null, p, false, true);
this.secureStorageService = new NodeEnvSecureStorageService(
this.storageService,
this.logService,

View File

@ -13,7 +13,7 @@ export class SendDeleteCommand {
}
try {
this.sendService.deleteWithServer(id);
await this.sendService.deleteWithServer(id);
return Response.success();
} catch (e) {
return Response.error(e);

View File

@ -67,7 +67,7 @@ export class UnlockCommand {
}
}
this.setNewSessionKey();
await this.setNewSessionKey();
const email = await this.stateService.getEmail();
const kdf = await this.stateService.getKdfType();
const kdfIterations = await this.stateService.getKdfIterations();

View File

@ -0,0 +1,42 @@
import * as lock from "proper-lockfile";
import { OperationOptions } from "retry";
import { LogService } from "jslib-common/abstractions/log.service";
import { LowdbStorageService as LowdbStorageServiceBase } from "jslib-node/services/lowdbStorage.service";
import { Utils } from "jslib-common/misc/utils";
const retries: OperationOptions = {
retries: 50,
minTimeout: 100,
maxTimeout: 250,
factor: 2,
};
export class LowdbStorageService extends LowdbStorageServiceBase {
constructor(
logService: LogService,
defaults?: any,
dir?: string,
allowCache = false,
private requireLock = false
) {
super(logService, defaults, dir, allowCache);
}
protected async lockDbFile<T>(action: () => T): Promise<T> {
if (this.requireLock && !Utils.isNullOrWhitespace(this.dataFilePath)) {
this.logService.info("acquiring db file lock");
return await lock.lock(this.dataFilePath, { retries: retries }).then((release) => {
try {
return action();
} finally {
release();
}
});
} else {
return action();
}
}
}