Skip to content

Commit 03dd250

Browse files
authored
Reconnect in event of failed ShardActions (#1255)
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.
1 parent 412f5a9 commit 03dd250

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/client/bridge/gateway/shard_runner.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,28 @@ impl ShardRunner {
136136
return self.request_restart().await;
137137
},
138138
Some(other) => {
139-
#[allow(clippy::let_underscore_must_use)]
140-
let _ = self.action(&other).await;
139+
if let Err(e) = self.action(&other).await {
140+
debug!(
141+
"[ShardRunner {:?}] Reconnecting due to error performing {:?}: {:?}",
142+
self.shard.shard_info(),
143+
other,
144+
e
145+
);
146+
match self.shard.reconnection_type() {
147+
ReconnectType::Reidentify => return self.request_restart().await,
148+
ReconnectType::Resume => {
149+
if let Err(why) = self.shard.resume().await {
150+
warn!(
151+
"[ShardRunner {:?}] Resume failed, reidentifying: {:?}",
152+
self.shard.shard_info(),
153+
why
154+
);
155+
156+
return self.request_restart().await;
157+
}
158+
},
159+
};
160+
}
141161
},
142162
None => {},
143163
}

src/gateway/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub enum InterMessage {
161161
Json(Value),
162162
}
163163

164+
#[derive(Debug)]
164165
#[non_exhaustive]
165166
pub enum ShardAction {
166167
Heartbeat,
@@ -169,6 +170,7 @@ pub enum ShardAction {
169170
}
170171

171172
/// The type of reconnection that should be performed.
173+
#[derive(Debug)]
172174
#[non_exhaustive]
173175
pub enum ReconnectType {
174176
/// Indicator that a new connection should be made by sending an IDENTIFY.

0 commit comments

Comments
 (0)