mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 09:22:55 +00:00
parse ip eagerly
This commit is contained in:
@@ -11,7 +11,12 @@ use crate::{
|
||||
use futures::TryFutureExt;
|
||||
use itertools::Itertools;
|
||||
use pq_proto::StartupMessageParams;
|
||||
use std::{io, net::SocketAddr, time::Duration};
|
||||
use std::{
|
||||
io,
|
||||
net::{IpAddr, SocketAddr},
|
||||
str::FromStr,
|
||||
time::Duration,
|
||||
};
|
||||
use thiserror::Error;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio_postgres::{
|
||||
@@ -182,11 +187,15 @@ impl ConnCfg {
|
||||
|
||||
// wrap TcpStream::connect with timeout
|
||||
let connect_with_timeout = |host, port| async move {
|
||||
let addrs = dns
|
||||
.resolve(host)
|
||||
.await
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
|
||||
.collect::<Vec<_>>();
|
||||
let addrs = if let Ok(ip) = IpAddr::from_str(host) {
|
||||
vec![ip]
|
||||
} else {
|
||||
dns.resolve(host)
|
||||
.await
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
|
||||
.collect()
|
||||
};
|
||||
|
||||
let timeout = timeout / addrs.len() as u32;
|
||||
|
||||
let mut last_err = None;
|
||||
|
||||
Reference in New Issue
Block a user