Await guild creation to fix a race condition
`Promise.all(...)` runs these simultaneously, yet role depends on the guild to be created first. This can lead to a race condition. I've awaited role creation too because the call to `Member.addToGuild(...)` relies on the role to be created.
This commit is contained in:
parent
4772731a17
commit
ff692c19b7
@ -140,25 +140,24 @@ router.post(
|
|||||||
|
|
||||||
const guild_id = Snowflake.generate();
|
const guild_id = Snowflake.generate();
|
||||||
|
|
||||||
const [guild] = await Promise.all([
|
const guild = await Guild.create({
|
||||||
Guild.create({
|
...body,
|
||||||
...body,
|
...template.serialized_source_guild,
|
||||||
...template.serialized_source_guild,
|
id: guild_id,
|
||||||
id: guild_id,
|
owner_id: req.user_id,
|
||||||
owner_id: req.user_id,
|
}).save();
|
||||||
}).save(),
|
|
||||||
Role.create({
|
await Role.create({
|
||||||
id: guild_id,
|
id: guild_id,
|
||||||
guild_id: guild_id,
|
guild_id: guild_id,
|
||||||
color: 0,
|
color: 0,
|
||||||
hoist: false,
|
hoist: false,
|
||||||
managed: true,
|
managed: true,
|
||||||
mentionable: true,
|
mentionable: true,
|
||||||
name: "@everyone",
|
name: "@everyone",
|
||||||
permissions: BigInt("2251804225").toString(), // TODO: where did this come from?
|
permissions: BigInt("2251804225").toString(), // TODO: where did this come from?
|
||||||
position: 0,
|
position: 0,
|
||||||
}).save(),
|
}).save();
|
||||||
]);
|
|
||||||
|
|
||||||
await Member.addToGuild(req.user_id, guild_id);
|
await Member.addToGuild(req.user_id, guild_id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user