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.

DnsNameResolver hangs for 5 seconds in InetAddress.getAllByName0 on Mac OSX

See original GitHub issue

Expected behavior

DnsNameResolver constructor should be fast, anything slow offloaded until actually used. Or a warning given that environment in badly configured.

This is an environmental problem, but raising because its a regression from java DNS which doesn’t hang like this.

Feel free to close if you don’t want to worry about it in Netty.

Actual behavior

constructor hangs at program startup

Steps to reproduce

    System.out.println("started " + new Date());

    ThreadFactory threadFactory = new DefaultThreadFactory("netty", true);
    NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(1, threadFactory);

    DnsNameResolverBuilder builder = new DnsNameResolverBuilder(eventLoopGroup.next())
            .channelType(NioDatagramChannel.class)
            .optResourceEnabled(false)
            .maxQueriesPerResolve(3)
            .recursionDesired(true);

    DnsNameResolver re = builder.build();

    System.out.println("finished " + new Date());

started Sat Feb 25 13:17:16 GMT 2017 finished Sat Feb 25 13:17:21 GMT 2017

Fix

Fix is http://justthesam.com/2016/10/fixing-java-net-inet6addressimpl-lookupallhostaddr-slowdown/

Netty version

4.1.8.Final

JVM version (e.g. java -version)

$ java -version java version “9-ea” Java™ SE Runtime Environment (build 9-ea+157) Java HotSpot™ 64-Bit Server VM (build 9-ea+157, mixed mode)

OS version (e.g. uname -a)

Darwin xxx 16.4.0 Darwin Kernel Version 16.4.0: Thu Dec 22 22:53:21 PST 2016; root:xnu-3789.41.3~3/RELEASE_X86_64 x86_64

"main" #1 prio=5 os_prio=31 tid=0x00007f8c60809800 nid=0x1d03 runnable [0x00007000027a3000]
   java.lang.Thread.State: RUNNABLE
	at java.net.Inet6AddressImpl.lookupAllHostAddr(java.base@9-ea/Native Method)
	at java.net.InetAddress$PlatformNameService.lookupAllHostAddr(java.base@9-ea/InetAddress.java:921)
	at java.net.InetAddress.getAddressesFromNameService(java.base@9-ea/InetAddress.java:1501)
	at java.net.InetAddress$NameServiceAddresses.get(java.base@9-ea/InetAddress.java:840)
	- locked <0x00000006cfce83e8> (a java.net.InetAddress$NameServiceAddresses)
	at java.net.InetAddress.getAllByName0(java.base@9-ea/InetAddress.java:1491)
	at java.net.InetAddress.getLocalHost(java.base@9-ea/InetAddress.java:1623)
	at sun.management.VMManagementImpl.getVmId(java.management@9-ea/VMManagementImpl.java:144)
	at sun.management.RuntimeImpl.getName(java.management@9-ea/RuntimeImpl.java:59)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@9-ea/NativeMethodAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@9-ea/DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(java.base@9-ea/Method.java:547)
	at io.netty.channel.DefaultChannelId.defaultProcessId(DefaultChannelId.java:121)
	at io.netty.channel.DefaultChannelId.<clinit>(DefaultChannelId.java:78)
	at io.netty.channel.AbstractChannel.newId(AbstractChannel.java:107)
	at io.netty.channel.AbstractChannel.<init>(AbstractChannel.java:79)
	at io.netty.channel.nio.AbstractNioChannel.<init>(AbstractNioChannel.java:84)
	at io.netty.channel.nio.AbstractNioMessageChannel.<init>(AbstractNioMessageChannel.java:42)
	at io.netty.channel.socket.nio.NioDatagramChannel.<init>(NioDatagramChannel.java:147)
	at io.netty.channel.socket.nio.NioDatagramChannel.<init>(NioDatagramChannel.java:115)
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(java.base@9-ea/Native Method)
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(java.base@9-ea/NativeConstructorAccessorImpl.java:62)
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(java.base@9-ea/DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(java.base@9-ea/Constructor.java:473)
	at java.lang.Class.newInstance(java.base@9-ea/Class.java:558)
	at io.netty.channel.ReflectiveChannelFactory.newChannel(ReflectiveChannelFactory.java:38)
	at io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:321)
	at io.netty.bootstrap.AbstractBootstrap.register(AbstractBootstrap.java:235)
	at io.netty.resolver.dns.DnsNameResolver.<init>(DnsNameResolver.java:249)
	at io.netty.resolver.dns.DnsNameResolverBuilder.build(DnsNameResolverBuilder.java:347)

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
testncommented, Mar 1, 2017

adding system property

-Djava.net.preferIPv4Stack=true

should help avoid the problem

1reaction
askiroscommented, Mar 9, 2017

It looks like an Mac OSX issue (resolution of the local host must happens inside java.lang.management.RuntimeMXBean#getName() causing the delay). The StackOverflow solution remove the delay.

Read more comments on GitHub >

github_iconTop Results From Across the Web

DnsNameResolver hangs for 5 seconds in InetAddress ...
DnsNameResolver hangs for 5 seconds in InetAddress.getAllByName0 on Mac OSX.
Read more >
Screen freezes for a few seconds - Apple Community
a few days ago, I began to notice my mac is getting issues with completely freezing up for a few seconds. The screen...
Read more >
Wednesday, December 27, 2017 - Ashwin Jayaprakash's Blog
... DnsNameResolver hangs for 5 seconds in InetAddress.getAllByName0 on Mac OSX · Issue #6454 · netty/netty · Hawt and spicy Java monitoring ...
Read more >
解决MacOS 下getByInetAddress 导致tomcat 启动项目很慢的问题
参考:. DnsNameResolver hangs for 5 seconds in InetAddress.getAllByName0 on Mac OSX · Jvm takes a long time to resolve ip-address for localhost ·...
Read more >
My mac's UI is randomly freezing for 5-10 seconds throughout ...
I have a 2017 27" iMac running macOS 10.14.6. Throughout the day the entire screen will freeze for a period of 5-10 seconds....
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