Skip to content

Commit 3ada8c9

Browse files
committed
Changed logic on task abort and panic scenarios
Signed-off-by: GilboaAWS <[email protected]>
1 parent f68b01d commit 3ada8c9

File tree

1 file changed

+28
-10
lines changed
  • glide-core/redis-rs/redis/src/cluster_async

1 file changed

+28
-10
lines changed

glide-core/redis-rs/redis/src/cluster_async/mod.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2770,16 +2770,34 @@ where
27702770
return Poll::Ready(Ok(()));
27712771
}
27722772
}
2773-
Some(Err(_)) => {
2774-
// Task panicked or was cancelled
2775-
trace!("Slot refresh task panicked or was cancelled");
2776-
let new_handle = Self::spawn_refresh_slots_task(
2777-
self.inner.clone(),
2778-
&RefreshPolicy::Throttable,
2779-
);
2780-
self.state =
2781-
ConnectionState::Recover(RecoverFuture::RefreshingSlots(new_handle));
2782-
return Poll::Ready(Ok(()));
2773+
Some(Err(join_err)) => {
2774+
if join_err.is_cancelled() {
2775+
// Task was intentionally aborted - don't treat as an error
2776+
trace!("Slot refresh task was aborted");
2777+
self.state = ConnectionState::PollComplete;
2778+
return Poll::Ready(Ok(()));
2779+
} else {
2780+
// Task panicked - try reconnecting to initial nodes as a recovery strategy
2781+
warn!("Slot refresh task panicked: {:?} - attempting recovery by reconnecting to initial nodes", join_err);
2782+
2783+
// TODO - consider a gracefully closing of the client
2784+
// Since a panic indicates a bug in the refresh logic,
2785+
// it might be safer to close the client entirely
2786+
self.state =
2787+
ConnectionState::Recover(RecoverFuture::ReconnectToInitialNodes(
2788+
Box::pin(ClusterConnInner::reconnect_to_initial_nodes(
2789+
self.inner.clone(),
2790+
)),
2791+
));
2792+
2793+
// Report this critical error to clients
2794+
let err = RedisError::from((
2795+
ErrorKind::ClientError,
2796+
"Slot refresh task panicked",
2797+
format!("{:?}", join_err),
2798+
));
2799+
return Poll::Ready(Err(err));
2800+
}
27832801
}
27842802
None => {
27852803
// Task is still running

0 commit comments

Comments
 (0)