diff --git a/client/transport/src/ws/mod.rs b/client/transport/src/ws/mod.rs index b24845d97d..ce40e6341f 100644 --- a/client/transport/src/ws/mod.rs +++ b/client/transport/src/ws/mod.rs @@ -326,7 +326,7 @@ impl WsTransportClientBuilder { &self, uri: Url, ) -> Result<(Sender>, Receiver>), WsHandshakeError> { - let mut target: Target = uri.try_into()?; + let mut target: Target = uri.clone().try_into()?; let mut err = None; // Only build TLS connector if `wss` in URL. @@ -340,7 +340,8 @@ impl WsTransportClientBuilder { tracing::debug!(target: LOG_TARGET, "Connecting to target: {:?}", target); // The sockaddrs might get reused if the server replies with a relative URI. - let sockaddrs = std::mem::take(&mut target.sockaddrs); + let sockaddrs = uri.socket_addrs(|| None).map_err(WsHandshakeError::ResolutionFailed)?; + for sockaddr in &sockaddrs { #[cfg(feature = "tls")] let tcp_stream = match connect(*sockaddr, self.connection_timeout, &target.host, connector.as_ref(), self.tcp_no_delay) @@ -407,7 +408,6 @@ impl WsTransportClientBuilder { } }; } - target.sockaddrs = sockaddrs; break; } @@ -550,8 +550,6 @@ impl From for WsError { /// Represents a verified remote WebSocket address. #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct Target { - /// Socket addresses resolved the host name. - sockaddrs: Vec, /// The host name (domain or IP address). host: String, /// The Host request header specifies the host and port number of the server to which the request is being sent. @@ -600,8 +598,7 @@ impl TryFrom for Target { let host_header = if let Some(port) = url.port() { format!("{host}:{port}") } else { host.to_string() }; - let sockaddrs = url.socket_addrs(|| None).map_err(WsHandshakeError::ResolutionFailed)?; - Ok(Self { sockaddrs, host, host_header, _mode, path_and_query: path_and_query.to_string(), basic_auth }) + Ok(Self { host, host_header, _mode, path_and_query: path_and_query.to_string(), basic_auth }) } }