If the bot is running and someones add the bot to another guild the cache can crash and become unresponsive if at the same time another event occurs in the guild.
For instance. if the bot FooBar joins a guild where another bot assigns all new members a role, then discord would send the signals GUILD_MEMBER_UPDATE & GUILD_CREATE simultaneously. It can happen that the GUILD_MEMBER_UPDATE is being processed before the GUILD_CREATE signal.
To prevent that, we can just handle all events that come in and check if a GenServer with the associated guild_id is already running.
Unfortunately, as the scenario sounds quite uncommon it happens quite often as a lot of larger guilds have bots that assign roles when a new member joins or have a welcome message posted in a channel.
If the bot is running and someones add the bot to another guild the cache can crash and become unresponsive if at the same time another event occurs in the guild.
For instance. if the bot FooBar joins a guild where another bot assigns all new members a role, then discord would send the signals
GUILD_MEMBER_UPDATE
&GUILD_CREATE
simultaneously. It can happen that theGUILD_MEMBER_UPDATE
is being processed before theGUILD_CREATE
signal.But as the guild may not exist yet, this can crash here: https://github.com/cronokirby/alchemy/blob/edb04294b10dfe16e2b40dcc31a4937f9382c0b6/lib/Cache/guilds.ex#L43
To prevent that, we can just handle all events that come in and check if a GenServer with the associated guild_id is already running.
Unfortunately, as the scenario sounds quite uncommon it happens quite often as a lot of larger guilds have bots that assign roles when a new member joins or have a welcome message posted in a channel.