Add a shared lock for Persist and ReactionRoles plugins to prevent race conditions

This commit is contained in:
Dragory 2020-05-22 20:35:15 +03:00
parent a5178dc78f
commit 47c5722060
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 14 additions and 3 deletions

View file

@ -71,8 +71,13 @@ export class PersistPlugin extends ZeppelinPlugin<TConfigSchema> {
@d.event("guildMemberAdd")
async onGuildMemberAdd(_, member: Member) {
const memberRolesLock = await this.locks.acquire(`member-roles-${member.id}`);
const persistedData = await this.persistedData.find(member.id);
if (!persistedData) return;
if (!persistedData) {
memberRolesLock.unlock();
return;
}
const toRestore: MemberOptions = {};
const config = this.getConfig();
@ -101,5 +106,7 @@ export class PersistPlugin extends ZeppelinPlugin<TConfigSchema> {
restoredData: restoredData.join(", "),
});
}
memberRolesLock.unlock();
}
}