Skip to content

Check number of available help channels hourly#1941

Closed
dementati wants to merge 2 commits into
mainfrom
feature/1903/fix-channel-inconsistencies
Closed

Check number of available help channels hourly#1941
dementati wants to merge 2 commits into
mainfrom
feature/1903/fix-channel-inconsistencies

Conversation

@dementati
Copy link
Copy Markdown
Contributor

@dementati dementati commented Nov 7, 2021

Solves the help channel count inconsistency from #1903.

If number of available help channels is incorrect, reload the HelpChannels cog.

If number of available help channels is incorrect,
reload the HelpChannels cog.
@dementati dementati added a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) p: 2 - normal Normal Priority a: help channels Related to the help channel system t: enhancement Changes or improvements to existing features s: needs review Author is waiting for someone to review and approve labels Nov 7, 2021
@dementati dementati requested a review from MarkKoz as a code owner November 7, 2021 20:25
@dementati dementati mentioned this pull request Nov 7, 2021
Copy link
Copy Markdown
Contributor

@Numerlor Numerlor left a comment

Choose a reason for hiding this comment

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

Would this help with the issue? I imagine if the count drops the admins will be notified sooner than the one hour period in most cases

Comment thread bot/exts/help_channels/_cog.py Outdated
@dementati
Copy link
Copy Markdown
Contributor Author

Would this help with the issue? I imagine if the count drops the admins will be notified sooner than the one hour period in most cases

I used the one-hour interval mentioned in the original issue, but perhaps that was referring to actually reloading the cog and not just checking the available channel count. Since getting the category channels in this manner doesn't seem to require an API call, I guess we could do it much more frequently at no cost.

"""
Check number of available help channels periodically.

If number of available help channels is incorrect, reload cog.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
If number of available help channels is incorrect, reload cog.
If the number of available help channels is incorrect, reload the cog.

Copy link
Copy Markdown
Contributor

@onerandomusername onerandomusername left a comment

Choose a reason for hiding this comment

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

This doesn't seem like it would fix the problem, and may add more problems in the long run.

Comment on lines +648 to +649
@tasks.loop(hours=1)
async def check_channel_consistency(self) -> None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe there is a possible race condition which would extend the amount of bugs.

If a channel is currently being closed while this runs, they would be awaiting an edit coroutine. This would allow the program to switch context and run the waiting task here.

However, the api would still be completing when this task decides to reload the cog, furthering the issue.

Its a race condition that would make the problem worse, imo.

A solution with that could be some asyncio.Locks, in order to not let the context switch to within here before a channel finishes closing and returns.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've looked into it when we opened the issue, but the cog is pretty resilient. If the closing process is still on the bot side, that shouldn't affect matters since it'll be canceled and resynced on startup.

If it's waiting on an API call from discord, I think it actually does not cancel until it's done, but I may be mistaken. Either way, the worst case scenario if it doesn't is that we'll move one channel twice, but it'll be to the same place both times, so nothing will break.

available_help_channels = set(_channel.get_category_channels(self.available_category))
if len(available_help_channels) != constants.HelpChannels.max_available:
log.trace("Unexpected number of available help channels, reloading cog...")
self.bot.reload_extension("bot.exts.help_channels")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why reload the whole cog? Is it not sufficient to just call init_available() again?

Copy link
Copy Markdown
Contributor

@MarkKoz MarkKoz Dec 25, 2021

Choose a reason for hiding this comment

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

In such case, I think you'd need to add a lock so it doesn't interfere with claim_channel().

@Bluenix2 Bluenix2 added s: waiting for author Waiting for author to address a review or respond to a comment and removed s: needs review Author is waiting for someone to review and approve labels Jan 22, 2022
@MarkKoz MarkKoz self-assigned this Jun 7, 2022
@Xithrius Xithrius added up for grabs Available for anyone to work on and removed up for grabs Available for anyone to work on labels Jul 9, 2022
@Xithrius
Copy link
Copy Markdown
Contributor

@MarkKoz Hello. What's your status on this PR?

Thanks.

@MarkKoz
Copy link
Copy Markdown
Contributor

MarkKoz commented Oct 26, 2022

@MarkKoz Hello. What's your status on this PR?

Thanks.

I do have some local changes but nothing was competed. I believe I ran into a difficult concurrency problem which led me to writing a custom lock, but I was having trouble achieving what I needed. I'll try to find it this weekend and see if this is something I can continue or not.

@MarkKoz
Copy link
Copy Markdown
Contributor

MarkKoz commented Nov 2, 2022

Work has started on the new help system, and given the amount of work this issue will require, I don't think it makes sense to continue. It's not high priority anyway.

@ChrisLovering
Copy link
Copy Markdown
Member

Agreed, lets not spend resources on this.

@ChrisLovering ChrisLovering deleted the feature/1903/fix-channel-inconsistencies branch August 16, 2023 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: backend Related to internal functionality and utilities (error_handler, logging, security, utils and core) a: help channels Related to the help channel system p: 2 - normal Normal Priority s: waiting for author Waiting for author to address a review or respond to a comment t: enhancement Changes or improvements to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants