diff options
| author | Zeyla Hellyer <[email protected]> | 2017-12-16 20:49:01 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2017-12-16 20:49:01 -0800 |
| commit | e6788838556d13d4a4f19253ce297ca2f72168ee (patch) | |
| tree | 72b5e315257fc609664e65eaf0c3992b19a51105 /src/client/bridge/gateway | |
| parent | Avoid an unwrap in args::parse_quotes (diff) | |
| download | serenity-e6788838556d13d4a4f19253ce297ca2f72168ee.tar.xz serenity-e6788838556d13d4a4f19253ce297ca2f72168ee.zip | |
Fix shards attempting to re-identify on their own
Fix shards by taking away their responsibility to re-identify, instead
shutting down shard runners and going through the shard queuer to
restart a shard runner and its associated shard.
This fixes the case where a running shard's session invalidates and
re-IDENTIFYs within 5 seconds before queued shard starts, causing a
cascading failure of sessions for new shards.
Diffstat (limited to 'src/client/bridge/gateway')
| -rw-r--r-- | src/client/bridge/gateway/shard_runner.rs | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/src/client/bridge/gateway/shard_runner.rs b/src/client/bridge/gateway/shard_runner.rs index a682693..43eebb8 100644 --- a/src/client/bridge/gateway/shard_runner.rs +++ b/src/client/bridge/gateway/shard_runner.rs @@ -1,4 +1,4 @@ -use gateway::{Shard, ShardAction}; +use gateway::{ReconnectType, Shard, ShardAction}; use internal::prelude::*; use internal::ws_impl::ReceiverExt; use model::event::{Event, GatewayEvent}; @@ -143,8 +143,14 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { let (event, action, successful) = self.recv_event(); - if let Some(ref action) = action { - let _ = self.action(action); + match action { + Some(ShardAction::Reconnect(ReconnectType::Reidentify)) => { + return self.request_restart() + }, + Some(other) => { + let _ = self.action(&other); + }, + None => {}, } if let Some(event) = event { @@ -173,11 +179,14 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { /// Returns fn action(&mut self, action: &ShardAction) -> Result<()> { match *action { - ShardAction::Autoreconnect => self.shard.autoreconnect(), + ShardAction::Reconnect(ReconnectType::Reidentify) => { + self.request_restart() + }, + ShardAction::Reconnect(ReconnectType::Resume) => { + self.shard.resume() + }, ShardAction::Heartbeat => self.shard.heartbeat(), ShardAction::Identify => self.shard.identify(), - ShardAction::Reconnect => self.shard.reconnect(), - ShardAction::Resume => self.shard.resume(), } } @@ -365,8 +374,15 @@ impl<H: EventHandler + Send + Sync + 'static> ShardRunner<H> { debug!("Attempting to auto-reconnect"); - if let Err(why) = self.shard.autoreconnect() { - error!("Failed to auto-reconnect: {:?}", why); + match self.shard.reconnection_type() { + ReconnectType::Reidentify => return (None, None, false), + ReconnectType::Resume => { + if let Err(why) = self.shard.resume() { + warn!("Failed to resume: {:?}", why); + + return (None, None, false); + } + }, } return (None, None, true); |