question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Netty DNS resolver fails to resolve computer's name on Windows

See original GitHub issue

When running on a VM with Windows 10, Netty DNS resolver cannot resolve computer’s name.

Expected behavior

When on Windows, Netty DNS resolver is able to resolve the computer’s name

Actual behavior

The current implementation throws an exception when one tries to resolve the computer’s name

Caused by: java.net.UnknownHostException: failed to resolve 'DESKTOP-BHE9K15' after 2 queries 
	at io.netty.resolver.dns.DnsResolveContext.finishResolve(DnsResolveContext.java:1013)
	at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:966)
	at io.netty.resolver.dns.DnsResolveContext.query(DnsResolveContext.java:414)
	at io.netty.resolver.dns.DnsResolveContext.tryToFinishResolve(DnsResolveContext.java:938)
	at io.netty.resolver.dns.DnsResolveContext.access$700(DnsResolveContext.java:63)
	at io.netty.resolver.dns.DnsResolveContext$2.operationComplete(DnsResolveContext.java:467)

Minimal yet complete reproducer code (or URL to code)

public class Application {

    public static void main(String[] args) throws Exception {
        // JDK
        InetAddress[] addresses = InetAddress.getAllByName("DESKTOP-BHE9K15");
        System.out.println(Arrays.asList(addresses));

        // JDK
        InetAddress localhost = InetAddress.getLocalHost();
        System.out.println(localhost);

        NioEventLoopGroup group = new NioEventLoopGroup();
        try {
            List<InetSocketAddress> result =
                    DefaultAddressResolverGroup.INSTANCE
                            .getResolver(group.next())
                            .resolveAll(InetSocketAddress.createUnresolved("DESKTOP-BHE9K15", 80))
                            .get();
            System.out.println("Netty DefaultAddressResolverGroup " + result);

            DnsNameResolverBuilder builder = new DnsNameResolverBuilder(group.next())
                    .channelType(NioDatagramChannel.class);
            DnsNameResolver resolver = builder.build();
            resolver.resolveAll("DESKTOP-BHE9K15")
                    .get();
        }
        finally {
            group.shutdownGracefully();
        }
    }
}

when the above code is executed, the result is:

[DESKTOP-BHE9K15/IPv4, DESKTOP-BHE9K15/IPv6]
DESKTOP-BHE9K15/IPv4
Netty DefaultAddressResolverGroup [DESKTOP-BHE9K15/IPv4:80, DESKTOP-BHE9K15/[IPv6]:80]
Exception in thread "main" java.util.concurrent.ExecutionException: java.net.UnknownHostException: failed to resolve 'DESKTOP-BHE9K15' after 2 queries 

Netty version

4.1.63.Final

JVM version (e.g. java -version)

java 11

OS version (e.g. uname -a)

Windows 10

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
violetaggcommented, Apr 19, 2021

@violetagg couldn’t we just call InetAddress.getLocalHost().getHostName() once in a static block ?

Yep and then apply the solution for localhost

0reactions
violetaggcommented, Apr 19, 2021

@violetagg can you do a PR ?

ok

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Boot API Gateway Unable to resolve name
But I managed to fix this problem by using the reactor.netty.http.client.HttpClient with DefaultAddressResolverGroup.INSTANCE resolver.
Read more >
DnsNameResolver xref - Netty
Attempting to send a DNS query or to resolve a domain name will fail once this ... the given hostname is the localhost/host...
Read more >
io.netty.resolver.dns.DnsNameResolver - Netty 4.1.72.Final 源码
15 */ 16 package io.netty.resolver.dns; 17 18 import io.netty.bootstrap. ... (Exception ignore) { 150 // Failed to get the system name search domain...
Read more >
Troubleshoot the UnknownHostException error in a Java ...
UnknownHostException is a common error message in Java applications. This error typically indicates that there was a DNS resolution failure.
Read more >
Vert.x Core Manual
You can also deploy verticles by specifying the verticle name. ... The DNS resolution is always done on the proxy server, to achieve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found