Do not try to resolve localhost with search domains (#30779)
* Prepopulate cache with localhost entries
This commit is contained in:
parent
73adc3194a
commit
f561146fa7
2 changed files with 23 additions and 2 deletions
|
|
@ -183,8 +183,6 @@ class AsyncDnsResolverIntegrationSpec
|
|||
}
|
||||
|
||||
"resolve localhost even though ndots is greater than 0" in {
|
||||
// This currently works because the nameserver resolves localhost, but in future should work because we've
|
||||
// implemented proper support for /etc/hosts
|
||||
val name = "localhost"
|
||||
val answer = resolve(name, DnsProtocol.Ip(ipv6 = false))
|
||||
withClue(answer) {
|
||||
|
|
|
|||
|
|
@ -39,6 +39,29 @@ private[io] final class AsyncDnsResolver(
|
|||
|
||||
implicit val ec: ExecutionContextExecutor = context.dispatcher
|
||||
|
||||
// avoid ever looking up localhost by pre-populating cache
|
||||
{
|
||||
val loopback = InetAddress.getLoopbackAddress
|
||||
val (ipv4Address, ipv6Address) = loopback match {
|
||||
case ipv6: Inet6Address => (InetAddress.getByName("127.0.0.1"), ipv6)
|
||||
case ipv4: Inet4Address => (ipv4, InetAddress.getByName("::1"))
|
||||
case unknown => throw new IllegalArgumentException(s"Loopback address was [$unknown]")
|
||||
}
|
||||
cache.put(
|
||||
"localhost" -> Ip(),
|
||||
DnsProtocol.Resolved("localhost", ARecord("localhost", Ttl.effectivelyForever, loopback) :: Nil),
|
||||
Ttl.effectivelyForever)
|
||||
cache.put(
|
||||
"localhost" -> Ip(ipv6 = false, ipv4 = true),
|
||||
DnsProtocol.Resolved("localhost", ARecord("localhost", Ttl.effectivelyForever, ipv4Address) :: Nil),
|
||||
Ttl.effectivelyForever)
|
||||
cache.put(
|
||||
"localhost" -> Ip(ipv6 = true, ipv4 = false),
|
||||
DnsProtocol.Resolved("localhost", ARecord("localhost", Ttl.effectivelyForever, ipv6Address) :: Nil),
|
||||
Ttl.effectivelyForever)
|
||||
|
||||
}
|
||||
|
||||
// For ask to DNS Client
|
||||
implicit val timeout: Timeout = Timeout(settings.ResolveTimeout)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue