From b4e034e3d8eb4f913e2a171eab0c25afad16eac2 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 14 Jun 2020 23:59:51 +0300 Subject: [PATCH] Mutes: Add locks to prevent multiple simultaneous attempts to mute a user --- backend/src/plugins/Mutes.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/src/plugins/Mutes.ts b/backend/src/plugins/Mutes.ts index a5df9e09..aafb510e 100644 --- a/backend/src/plugins/Mutes.ts +++ b/backend/src/plugins/Mutes.ts @@ -150,8 +150,11 @@ export class MutesPlugin extends ZeppelinPlugin { reason: string = null, muteOptions: MuteOptions = {}, ): Promise { + const lock = await this.locks.acquire(`mute-${userId}`); + const muteRole = this.getConfig().mute_role; if (!muteRole) { + lock.unlock(); this.throwRecoverablePluginError(ERRORS.NO_MUTE_ROLE_IN_CONFIG); } @@ -287,6 +290,8 @@ export class MutesPlugin extends ZeppelinPlugin { }); } + lock.unlock(); + return { case: theCase, notifyResult,