Skip to content

Commit

Permalink
fix: using tran.getForUpdate for vaults renaming and sigchain claim…
Browse files Browse the repository at this point in the history
… creation
  • Loading branch information
tegefaulkes committed Aug 22, 2022
1 parent 4fe9492 commit 1b109d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/notifications/NotificationsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class NotificationsManager {
// Only keep the message if the sending node has the correct permissions
if (Object.keys(nodePerms.gestalt).includes('notify')) {
// If the number stored in notificationsDb >= 10000
let numMessages = await tran.getForUpdate<number>(
let numMessages = await tran.get<number>(
this.notificationsMessageCounterDbPath,
);
if (numMessages === undefined) {
Expand Down Expand Up @@ -316,7 +316,7 @@ class NotificationsManager {

await tran.lock(this.notificationsMessageCounterDbPath.toString());
const notificationIds = await this.getNotificationIds('all', tran);
const numMessages = await tran.getForUpdate<number>(
const numMessages = await tran.get<number>(
this.notificationsMessageCounterDbPath,
);
if (numMessages !== undefined) {
Expand Down Expand Up @@ -403,7 +403,7 @@ class NotificationsManager {
tran: DBTransaction,
): Promise<void> {
await tran.lock(this.notificationsMessageCounterDbPath.toString());
const numMessages = await tran.getForUpdate<number>(
const numMessages = await tran.get<number>(
this.notificationsMessageCounterDbPath,
);
if (numMessages === undefined) {
Expand Down
12 changes: 12 additions & 0 deletions src/vaults/VaultManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ class VaultManager {
}

await this.vaultLocks.withF([vaultId, RWLockWriter, 'write'], async () => {
// Ensure protection from write skew
await tran.getForUpdate([
...this.vaultsDbPath,
vaultsUtils.encodeVaultId(vaultId),
VaultInternal.nameKey,
]);
const vaultMeta = await this.getVaultMeta(vaultId, tran);
if (vaultMeta == null) return;
const vaultName = vaultMeta.vaultName;
Expand Down Expand Up @@ -452,6 +458,12 @@ class VaultManager {
if (await this.getVaultId(newVaultName, tran)) {
throw new vaultsErrors.ErrorVaultsVaultDefined();
}
// Ensure protection from write skew
await tran.getForUpdate([
...this.vaultsDbPath,
vaultsUtils.encodeVaultId(vaultId),
VaultInternal.nameKey,
]);
// Checking if vault exists
const vaultMetadata = await this.getVaultMeta(vaultId, tran);
if (vaultMetadata == null) {
Expand Down

0 comments on commit 1b109d9

Please sign in to comment.