Skip to content

Commit 514066f

Browse files
committed
fix(core): avoid reverse DNS lookup in socket address formatting
- Replace socket_addr.to_string() calls with explicit format!() to prevent reverse DNS lookups - Add socket_addr parameter to MultiplexedConnection::new_with_stream() for accurate address tracking - Update address_string construction in PushManager initialization to use actual socket address when available - Pass socket_addr through client connection flow to cluster async module Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
1 parent e7973b7 commit 514066f

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

glide-core/redis-rs/redis/src/aio/multiplexed_connection.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use pin_project_lite::pin_project;
2525
use std::collections::VecDeque;
2626
use std::fmt;
2727
use std::fmt::Debug;
28+
use std::net::SocketAddr;
2829
use std::pin::Pin;
2930
use std::sync::atomic::{AtomicBool, Ordering};
3031
use std::sync::Arc;
@@ -605,6 +606,7 @@ impl MultiplexedConnection {
605606
stream,
606607
std::time::Duration::MAX,
607608
glide_connection_options,
609+
None, // No socket_addr available in this path
608610
)
609611
.await
610612
}
@@ -616,6 +618,7 @@ impl MultiplexedConnection {
616618
stream: C,
617619
response_timeout: std::time::Duration,
618620
glide_connection_options: GlideConnectionOptions,
621+
socket_addr: Option<SocketAddr>,
619622
) -> RedisResult<(Self, impl Future<Output = ()>)>
620623
where
621624
C: Unpin + AsyncRead + AsyncWrite + Send + 'static,
@@ -626,10 +629,17 @@ impl MultiplexedConnection {
626629
let (mut pipeline, driver) =
627630
Pipeline::new(codec, glide_connection_options.disconnect_notifier);
628631
let driver = Box::pin(driver);
632+
633+
// Use the actual socket address if available, otherwise fall back to connection_info.addr
634+
let address_string = if let Some(socket_addr) = socket_addr {
635+
format!("{}:{}", socket_addr.ip(), socket_addr.port())
636+
} else {
637+
connection_info.addr.to_string()
638+
};
629639
let pm = PushManager::new(
630640
glide_connection_options.push_sender,
631641
glide_connection_options.pubsub_synchronizer,
632-
Some(connection_info.addr.to_string()),
642+
Some(address_string),
633643
);
634644

635645
pipeline.set_push_manager(pm.clone());

glide-core/redis-rs/redis/src/client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ impl Client {
445445
con,
446446
response_timeout,
447447
glide_connection_options,
448+
socket_addr,
448449
)
449450
.await
450451
.map(|res| (res.0, res.1, ip))

glide-core/redis-rs/redis/src/cluster_async/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,9 @@ where
12901290
.await
12911291
.get_node();
12921292
let node_address = if let Some(socket_addr) = socket_addr {
1293-
socket_addr.to_string()
1293+
// Use format! to avoid reverse DNS lookup that socket_addr.to_string() performs
1294+
let addr = format!("{}:{}", socket_addr.ip(), socket_addr.port());
1295+
addr
12941296
} else {
12951297
node_addr
12961298
};
@@ -2250,7 +2252,12 @@ where
22502252
let conn_lock =
22512253
inner.conn_lock.read().expect(MUTEX_READ_ERR);
22522254
socket_addresses.find_map(|socket_addr| {
2253-
conn_lock.node_for_address(&socket_addr.to_string())
2255+
let addr_str = format!(
2256+
"{}:{}",
2257+
socket_addr.ip(),
2258+
socket_addr.port()
2259+
);
2260+
conn_lock.node_for_address(&addr_str)
22542261
})
22552262
},
22562263
);

0 commit comments

Comments
 (0)