Skip to content

Commit 0489191

Browse files
committed
gateway: add configurable DNS TXT resolve timeout
Add a new `dns_resolve` timeout setting in the proxy timeouts config to prevent DNS TXT record lookups from hanging indefinitely when resolving app addresses. Default timeout is 5 seconds, configurable via gateway.toml: [core.proxy.timeouts] dns_resolve = "5s"
1 parent 139d588 commit 0489191

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

gateway/gateway.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ handshake = "5s"
7979

8080
# Timeout for top n hosts selection
8181
cache_top_n = "30s"
82+
# Timeout for DNS TXT record resolution (app address lookup).
83+
dns_resolve = "5s"
8284

8385
# Enable data transfer timeouts below. This might impact performance. Turn off if
8486
# bad performance is observed.

gateway/src/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ pub struct Timeouts {
9999
#[serde(with = "serde_duration")]
100100
pub cache_top_n: Duration,
101101

102+
/// Timeout for DNS TXT record resolution (app address lookup).
103+
#[serde(with = "serde_duration")]
104+
pub dns_resolve: Duration,
105+
102106
pub data_timeout_enabled: bool,
103107
#[serde(with = "serde_duration")]
104108
pub idle: Duration,

gateway/src/proxy/tls_passthough.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ pub(crate) async fn proxy_with_sni(
7979
) -> Result<()> {
8080
let ns_prefix = &state.config.proxy.app_address_ns_prefix;
8181
let compat = state.config.proxy.app_address_ns_compat;
82-
let addr = resolve_app_address(ns_prefix, sni, compat)
82+
let dns_timeout = state.config.proxy.timeouts.dns_resolve;
83+
let addr = timeout(dns_timeout, resolve_app_address(ns_prefix, sni, compat))
8384
.await
85+
.context("DNS TXT resolve timeout")?
8486
.context("failed to resolve app address")?;
8587
debug!("target address is {}:{}", addr.app_id, addr.port);
8688
proxy_to_app(state, inbound, buffer, &addr.app_id, addr.port).await

0 commit comments

Comments
 (0)