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

Handle InvalidateSession in connect_sharded? #97

Closed
ArtemGr opened this issue Jan 13, 2017 · 1 comment
Closed

Handle InvalidateSession in connect_sharded? #97

ArtemGr opened this issue Jan 13, 2017 · 1 comment
Labels

Comments

@ArtemGr
Copy link
Contributor

ArtemGr commented Jan 13, 2017

Hi, discord-rs wizard(s)!

I'm using the connect_sharded now because the bot have reached the 2500 limit.

With two shards it works fine!
But if I try to start three or four shards I get the "Expected Ready during handshake" error.

The code looks like this

let total_shards = 3;
for shard_id in 0 .. total_shards {
    std::thread::Builder::new().name (fomat! ("shard " (shard_id) ", dice_thread"))
        .spawn (move || dice::dice_thread (shard_id, total_shards)) .expect ("!spawn");
}

pub fn dice_thread (shard_id: u8, total_shards: u8) {
    ...
    let (mut dc, ready_ev) = bot.connect_sharded (shard_id, total_shards) .expect ("!connect");

And the log is:

DEBUG:discord::connection: Unexpected event: InvalidateSession
thread 'shard 0, dice_thread' panicked at '!connect: Protocol("Expected Ready during handshake")', /buildslave/rust-bui
note: Run with `RUST_BACKTRACE=1` for a backtrace.

I wonder what the InvalidateSession event tells us?

At the very least it might be better to handle it in order to panic with a better error message or something.

@ArtemGr
Copy link
Contributor Author

ArtemGr commented Jan 13, 2017

zeyla on "Discord API" pointed out that a five-second pause needed between the connections:
"there is a ratelimit of 1 gateway connection per 5 seconds per IP address, but I'd wait 6 or 7 to be safe(edited)"

Adding the pause solved the problem for me.

I will leave the issue open because the error message and/or documetation can be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants