Skip to content

Commit

Permalink
Changed initial connections error to return the last error
Browse files Browse the repository at this point in the history
  • Loading branch information
barshaul committed Sep 2, 2023
1 parent f16ae47 commit 75c477e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions redis/src/cluster_async/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,18 @@ where
) -> RedisResult<ConnectionMap<C>> {
let initial_nodes: Vec<(String, Option<SocketAddr>)> =
Self::try_to_expand_initial_nodes(initial_nodes).await;
let err = Arc::new(Mutex::new("".to_string()));
let connections = stream::iter(initial_nodes.iter().cloned())
.map(|node| {
let cloned_err = err.clone();
let params = params.clone();
async move {
let result = connect_and_check(&node.0, params, node.1).await;
match result {
Ok(conn) => Some((node.0, async { conn }.boxed().shared())),
Err(e) => {
trace!("Failed to connect to initial node: {:?}", e);
*cloned_err.clone().lock().unwrap() = e.to_string();
None
}
}
Expand All @@ -558,9 +561,12 @@ where
)
.await;
if connections.is_empty() {
let err_guard = err.lock().unwrap();

return Err(RedisError::from((
ErrorKind::IoError,
"Failed to create initial connections",
err_guard.clone(),
)));
}
Ok(connections)
Expand Down

0 comments on commit 75c477e

Please sign in to comment.