Skip to content

Fix category cache issue#900

Merged
SebastiaanZ merged 1 commit into
masterfrom
fix-category-cache-issue
Apr 21, 2020
Merged

Fix category cache issue#900
SebastiaanZ merged 1 commit into
masterfrom
fix-category-cache-issue

Conversation

@jb3
Copy link
Copy Markdown
Member

@jb3 jb3 commented Apr 21, 2020

After experiencing a reconnect from Discord, the channel cache we were using in the help cog began to fall apart and claimed there were 29 channels in the available category and no channels elsewhere.

(Blue line marks disconnect)

image

This PR forces retrieval of the channels in the guild from the bot cache in the get_category_channels method through the usage of bot.get_guild instead of category.guild.channels, since the latter fell apart after a reconnect.

@jb3 jb3 requested a review from a team as a code owner April 21, 2020 13:17
@jb3 jb3 requested review from MrHemlock and manusaurio and removed request for a team April 21, 2020 13:17
Copy link
Copy Markdown
Contributor

@scragly scragly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alterations look good to me, thanks for your work!

Copy link
Copy Markdown
Contributor

@SebastiaanZ SebastiaanZ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks good.

Just to add some context to those wondering what was going on: The channels cache we accessed through the guild attribute of a reference to the Available category was completely out of sync with actual channel lay-out of the guild. This started happening after a disconnect/restart of the shard's websocket/gateway connection:

2020-04-21 01:18:47 | discord.gateway | WARNING | Shard ID None has stopped responding to the gateway. Closing and restarting.

Somehow, that channel cache registered all channels being moved to the available category, but not the moves of channels out of that category. That caused the effect we saw in the stats: All the channels appeared to be in the Available category.

We confirmed that this channels cache was wrong and different from the one access via bot.guild.channels using our internal eval. The latter, bot.guild.channels did reflect the actual state of the channels on our server.

Internal eval results:

# Using the `channels` accessed through the category reference:
In [4]: print(sum(1 for _ in bot.get_cog("HelpChannels").get_category_channels(bot.get_cog("HelpChannels").available_category)))
29

In [5]: print(sum(1 for _ in bot.get_cog("HelpChannels").get_category_channels(bot.get_cog("HelpChannels").dormant_category)))
0

# -------------------------------------
# Using other means:

In [10]: available = guild.get_channel(691405807388196926)
    ...: print(len(available.channels))
    ...: 
2

In [14]: import discord
    ...: occupied = 696958401460043776
    ...: print(sum(isinstance(c, discord.TextChannel) and c.category_id == occupied for c in guild.channels))
    ...: 
10

In [18]: hc = bot.get_cog("HelpChannels")
    ...: channels = hc.bot.get_guild(267624335836053506).channels
    ...: print(sum(isinstance(c, discord.TextChannel) and c.category_id == 696958401460043776 for c in channels))
    ...: 
10

@SebastiaanZ SebastiaanZ merged commit 25c93b7 into master Apr 21, 2020
@SebastiaanZ SebastiaanZ deleted the fix-category-cache-issue branch April 21, 2020 13:48
@MarkKoz MarkKoz added a: help channels Related to the help channel system t: bug Something isn't working labels May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: help channels Related to the help channel system t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants