Skip to content

Commit

Permalink
Reconnect in event of failed ShardActions (#1255)
Browse files Browse the repository at this point in the history
This removes a `let _ = ...` which was silently causing some resume failures to become permanent, causing the shard to crash the next time it attempted to use its (closed) WS client. This is replaced with code to trigger a further resume and/or reidentification attempt.

In the worst case, this will attempt one further resume before "promoting" the resume into a full reidentify. The `ShardQueuer` is then already responsible for repeated full reidentify attempts from that point on.
  • Loading branch information
FelixMcFelix committed Mar 18, 2021
1 parent 412f5a9 commit 03dd250
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/client/bridge/gateway/shard_runner.rs
Expand Up @@ -136,8 +136,28 @@ impl ShardRunner {
return self.request_restart().await;
},
Some(other) => {
#[allow(clippy::let_underscore_must_use)]
let _ = self.action(&other).await;
if let Err(e) = self.action(&other).await {
debug!(
"[ShardRunner {:?}] Reconnecting due to error performing {:?}: {:?}",
self.shard.shard_info(),
other,
e
);
match self.shard.reconnection_type() {
ReconnectType::Reidentify => return self.request_restart().await,
ReconnectType::Resume => {
if let Err(why) = self.shard.resume().await {
warn!(
"[ShardRunner {:?}] Resume failed, reidentifying: {:?}",
self.shard.shard_info(),
why
);

return self.request_restart().await;
}
},
};
}
},
None => {},
}
Expand Down
2 changes: 2 additions & 0 deletions src/gateway/mod.rs
Expand Up @@ -161,6 +161,7 @@ pub enum InterMessage {
Json(Value),
}

#[derive(Debug)]
#[non_exhaustive]
pub enum ShardAction {
Heartbeat,
Expand All @@ -169,6 +170,7 @@ pub enum ShardAction {
}

/// The type of reconnection that should be performed.
#[derive(Debug)]
#[non_exhaustive]
pub enum ReconnectType {
/// Indicator that a new connection should be made by sending an IDENTIFY.
Expand Down

0 comments on commit 03dd250

Please sign in to comment.