Skip to content

Commit d450f12

Browse files
committed
fix: swap status monitor dns resolver with native resolver (#2432)
<!-- Please make sure there is an issue that this PR is correlated to. --> ## Changes <!-- If there are frontend changes, please include screenshots. -->
1 parent 36252ec commit d450f12

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

packages/core/api/status/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ game-resolve-name-id.workspace = true
4141
game-namespace-resolve-name-id.workspace = true
4242

4343
token-create.workspace = true
44-
hickory-resolver = "0.25.1"
4544
rivet-config.workspace = true
4645
rivet-env.workspace = true
4746

packages/core/api/status/src/route/actor.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
collections::HashMap,
3-
net::{IpAddr, SocketAddr},
3+
net::{IpAddr, SocketAddr, ToSocketAddrs},
44
time::Duration,
55
};
66

@@ -263,7 +263,7 @@ pub async fn status(
263263
#[tracing::instrument]
264264
async fn test_actor_connection(hostname: &str, port: u16, actor_origin: &str) -> GlobalResult<()> {
265265
// Look up IP for the actor's host
266-
let gg_ips = lookup_dns(hostname).await?;
266+
let gg_ips = lookup_dns(hostname, port).await?;
267267
ensure_with!(
268268
!gg_ips.is_empty(),
269269
INTERNAL_STATUS_CHECK_FAILED,
@@ -315,13 +315,19 @@ async fn test_actor_connection(hostname: &str, port: u16, actor_origin: &str) ->
315315

316316
/// Returns the IP addresses for a given hostname.
317317
#[tracing::instrument]
318-
async fn lookup_dns(hostname: &str) -> GlobalResult<Vec<IpAddr>> {
319-
let resolver = hickory_resolver::Resolver::builder_tokio()?.build();
320-
let addrs = resolver
321-
.lookup_ip(hostname)
322-
.await?
323-
.into_iter()
324-
.collect::<Vec<IpAddr>>();
318+
async fn lookup_dns(hostname: &str, port: u16) -> GlobalResult<Vec<IpAddr>> {
319+
let addr = format!("{hostname}:{port}");
320+
321+
// Use native resolver in a blocking task
322+
let addrs = tokio::task::spawn_blocking(move || {
323+
GlobalResult::Ok(
324+
addr.to_socket_addrs()?
325+
.into_iter()
326+
.map(|x| x.ip())
327+
.collect::<Vec<_>>(),
328+
)
329+
})
330+
.await??;
325331

326332
Ok(addrs)
327333
}

packages/core/api/status/src/route/matchmaker.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
net::{IpAddr, SocketAddr},
2+
net::{IpAddr, SocketAddr, ToSocketAddrs},
33
time::Duration,
44
};
55

@@ -194,7 +194,7 @@ async fn test_lobby_connection(
194194
let token = &player.token;
195195

196196
// Look up IP for GG nodes
197-
let gg_ips = lookup_dns(hostname).await?;
197+
let gg_ips = lookup_dns(hostname, 443).await?;
198198
ensure_with!(
199199
!gg_ips.is_empty(),
200200
INTERNAL_STATUS_CHECK_FAILED,
@@ -245,17 +245,23 @@ async fn test_lobby_connection(
245245
}
246246

247247
/// Returns the IP addresses for a given hostname.
248-
async fn lookup_dns(hostname: &str) -> GlobalResult<Vec<IpAddr>> {
249-
let resolver = hickory_resolver::Resolver::builder_tokio()?.build();
250-
let addrs = resolver
251-
.lookup_ip(hostname)
252-
.await?
253-
.into_iter()
254-
.collect::<Vec<IpAddr>>();
248+
#[tracing::instrument]
249+
async fn lookup_dns(hostname: &str, port: u16) -> GlobalResult<Vec<IpAddr>> {
250+
let addr = format!("{hostname}:{port}");
251+
252+
// Use native resolver in a blocking task
253+
let addrs = tokio::task::spawn_blocking(move || {
254+
GlobalResult::Ok(
255+
addr.to_socket_addrs()?
256+
.into_iter()
257+
.map(|x| x.ip())
258+
.collect::<Vec<_>>(),
259+
)
260+
})
261+
.await??;
255262

256263
Ok(addrs)
257264
}
258-
259265
/// Tests HTTP connectivity to a hostname for a given address.
260266
///
261267
/// This lets us isolate of a specific GG IP address is not behaving correctly.

0 commit comments

Comments
 (0)