diff --git a/redis/src/cluster_async/mod.rs b/redis/src/cluster_async/mod.rs index 4907c8d59a..af27f2bba6 100644 --- a/redis/src/cluster_async/mod.rs +++ b/redis/src/cluster_async/mod.rs @@ -534,8 +534,10 @@ where ) -> RedisResult> { let initial_nodes: Vec<(String, Option)> = 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; @@ -543,6 +545,7 @@ where 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 } } @@ -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)