Skip to content

Commit

Permalink
Do asynchronous DNS lookups in ServerAddr::socket_addrs
Browse files Browse the repository at this point in the history
  • Loading branch information
paolobarbolini authored and Jarema committed Jan 6, 2024
1 parent 0424068 commit 8c783e0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions async-nats/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl Connector {

let socket_addrs = server_addr
.socket_addrs()
.await
.map_err(|err| ConnectError::with_source(crate::ConnectErrorKind::Dns, err))?;
for socket_addr in socket_addrs {
match self
Expand Down
6 changes: 3 additions & 3 deletions async-nats/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ use std::fmt::Display;
use std::future::Future;
use std::iter;
use std::mem;
use std::net::{SocketAddr, ToSocketAddrs};
use std::net::SocketAddr;
use std::option;
use std::pin::Pin;
use std::slice;
Expand Down Expand Up @@ -1427,8 +1427,8 @@ impl ServerAddr {
}

/// Return the sockets from resolving the server address.
pub fn socket_addrs(&self) -> io::Result<impl Iterator<Item = SocketAddr>> {
(self.host(), self.port()).to_socket_addrs()
pub async fn socket_addrs(&self) -> io::Result<impl Iterator<Item = SocketAddr> + '_> {
tokio::net::lookup_host((self.host(), self.port())).await
}
}

Expand Down

0 comments on commit 8c783e0

Please sign in to comment.