Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sleep between calls to add user to channels #124

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mickmister
Copy link
Contributor

@mickmister mickmister commented Feb 23, 2024

Summary

There is an issue occurring with the Welcomebot and the Playbooks plugin's Channel Actions "automatically add to channel category" feature, where the user is inadvertently having duplicate channel categories created with the same name. We believe is due to a race condition of adding the user to multiple channels semi-simultaneously. More info in the tickets linked below.

This PR adds a sleep in between adding a user to multiple channels, to avoid this situation. A more holistic solution of handling this issue in the core product is discussed in the Jira ticket below, though this PR can resolve this before the core issue is addressed.

Ticket Link

Fixes #120

https://mattermost.atlassian.net/browse/MM-54003

@mickmister mickmister requested a review from hanzei February 23, 2024 18:34
@@ -113,6 +113,7 @@ func (p *Plugin) renderWelcomeMessage(messageTemplate MessageTemplate, configMes

for _, channelName := range configAction.ChannelsAddedTo {
p.joinChannel(action, channelName)
time.Sleep(time.Second)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hanzei 0/5 on if this should be done this way. Lots of cons come with this:

  • Channel actions may not be used on a server, so this sleep would be for naught
  • The sleep may be unnecessarily long, especially when we're adding the user to a lot of channels
  • It may not solve the problem in every case

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm in favour of doing it this way, as it should fix the issue out-of-the-box. A config setting seems cumbersome and confusing for admins.

This code only runs once per user, i.e. on their creation. Having a delay is justifiable. Even with 60 channels (!), that is just one minute of wait time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though I wonder if the user is pinged with a "ding" every second. I haven't actually seen this in action yet

Choose a reason for hiding this comment

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

Dear Michael @mickmister and Ben @hanzei, thanks for providing this fix and your thoughts. I agree with the concerns, though. This wait-time as the only measure is rather unreliable. You can never guess an optimal wait-time for all cases. Sometimes you bother users with unexpected long wait-times, sometimes you bother them with duplicate categories.

Suggestions:

  1. Is there a way to determine if a category needs to be created, but creation has not yet been triggered (this might be the tricky part), check if the category already exists, wait-retry if is it not yet created but triggered, add member if it is already created?

  2. Is there a way to wait only if a category assignment is configured in the channel actions?

What do you think about these suggestions?

That's of course more challenging to implement, but you might have an idea how to achieve that. Thank you very much for taking these considerations into account!

Copy link
Contributor

@Kshitij-Katiyar Kshitij-Katiyar Apr 16, 2024

Choose a reason for hiding this comment

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

@mickmister Are you looking into this or we should?

Copy link
Contributor Author

@mickmister mickmister Apr 16, 2024

Choose a reason for hiding this comment

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

@hanzei Note that there is already a property on the WelcomeMessage struct called DelayInSeconds, which allows the admin to set a delay between certain operations, so introducing another part of the config with this pattern would not be out of the ordinary. 0/5 but in this case it may make sense to allow the admin to set this, so we don't have to revisit it if the wait we choose is not high enough.

@hanzei hanzei added the 2: Dev Review Requires review by a core committer label Feb 25, 2024
Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

@mickmister mickmister added the 3: QA Review Requires review by a QA tester label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester
Projects
None yet
4 participants