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

Fix bug that will only start one shard #194

Merged
merged 5 commits into from
Mar 3, 2021

Conversation

DRSchlaubi
Copy link
Member

@DRSchlaubi DRSchlaubi commented Mar 1, 2021

All shards will get started by this function:

   /**
     * Calls [Gateway.start] on each Gateway in [gateways], changing the [GatewayConfiguration.shard] for each Gateway.
     */
    suspend fun start(configuration: GatewayConfiguration): Unit =
        gateways.entries.forEach { (shard, gateway) ->
            val config = configuration.copy(shard = configuration.shard.copy(index = shard))
             gateway.start(config)
        }
    

The problem is that Gateway.start() is a suspending functions which suspends as long as the gateway is active
As forEach executes all elements one by one on the same thread the first element calls gateway.start and blocks the coroutines
Therefore the other shards never get started.

I fixed this by wrapping start in coroutineScope {} and launch a new coroutine for every gateway.
This should still let the behavior remain, that Kord.login/MasterGateway.start blocks as long as the Gateway is active but each Gateway instance is in it's on child coroutine

Fixes #195

@DRSchlaubi
Copy link
Member Author

I reverted the changes to shutdown and logout as discussed that it's not necessary: https://discord.com/channels/556525343595298817/631147109311053844/815904781653770272

@HopeBaron HopeBaron changed the base branch from 0.7.x to sharding-changes March 3, 2021 10:06
@HopeBaron HopeBaron merged commit 030a334 into kordlib:sharding-changes Mar 3, 2021
HopeBaron added a commit that referenced this pull request Mar 3, 2021
@DRSchlaubi DRSchlaubi mentioned this pull request Mar 3, 2021
@HopeBaron HopeBaron mentioned this pull request Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kord only starts one shard
3 participants