CioDnsResolver

fun CioDnsResolver(server: String, port: Int = 53, timeout: Duration = 5.seconds): suspend (hostname: String) -> List<String>(source)

Returns a CIOEngineConfig.dnsResolver that performs hostname lookups by speaking RFC 1035 directly over UDP using ktor-network. Fully non-blocking; supports a per-query timeout.

Issues A and AAAA queries in parallel on a single UDP socket and returns the merged result with IPv6 addresses listed first (per RFC 6724 / RFC 8305 destination preference). If only one response arrives before timeout, whatever was received is returned; if neither arrives, IOException is thrown.

Bypasses the OS name service entirely — it does not consult /etc/hosts, mDNS, or NSS-configured local resolvers. Use JvmDnsResolver when those need to keep working.

Unlike Netty's DnsNameResolver, this implementation does not auto-discover the system resolver (/etc/resolv.conf, JNDI, Windows registry); server must be passed explicitly.

HttpClient(CIO) {
engine {
dnsResolver = CioDnsResolver(server = "1.1.1.1", timeout = 3.seconds)
}
}

Limitations of this minimal implementation:

  • A / AAAA records only; CNAME chains are not followed

  • No TCP fallback when the response has the TC (truncation) flag set

  • No retry; wrap with your own retry policy if needed

  • UDP is not supported on JS/Wasm; calling there will throw

Report a problem