fix: One source of transaction deadlock when invites > pg pool (#1696)
* fix: One source of transaction deadlock when invites > pg pool * lint
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
// @flow
|
||||
import { Transaction } from "sequelize";
|
||||
import { ValidationError } from "../errors";
|
||||
import { User, Event, GroupUser } from "../models";
|
||||
import { sequelize } from "../sequelize";
|
||||
@ -16,29 +17,27 @@ export default async function userSuspender({
|
||||
throw new ValidationError("Unable to suspend the current user");
|
||||
}
|
||||
|
||||
let transaction;
|
||||
try {
|
||||
transaction = await sequelize.transaction();
|
||||
await sequelize.transaction(async (transaction: Transaction) => {
|
||||
await user.update(
|
||||
{
|
||||
suspendedById: actorId,
|
||||
suspendedAt: new Date(),
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
|
||||
await user.update({
|
||||
suspendedById: actorId,
|
||||
suspendedAt: new Date(),
|
||||
});
|
||||
await GroupUser.destroy({ where: { userId: user.id }, transaction });
|
||||
|
||||
await GroupUser.destroy({ where: { userId: user.id } });
|
||||
} catch (err) {
|
||||
if (transaction) {
|
||||
await transaction.rollback();
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
await Event.create({
|
||||
name: "users.suspend",
|
||||
actorId,
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
data: { name: user.name },
|
||||
ip,
|
||||
await Event.create(
|
||||
{
|
||||
name: "users.suspend",
|
||||
actorId,
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
data: { name: user.name },
|
||||
ip,
|
||||
},
|
||||
{ transaction }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user