Handle `InvalidateSession` in `connect_sharded`?
ArtemGr opened this issue · comments
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.
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.