Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do asynchronous DNS lookups in ServerAddr::socket_addrs #1191

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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