JDK-8170910: Avoid 5 second localhost lookup behavior on OSX
Michael McMahon
michael.x.mcmahon at oracle.com
Fri Apr 5 16:12:51 UTC 2019
I've spent some time trying to reproduce this on 10.13 but have not been
able.
I have disabled all the services as suggested (including some additional)
such that the dns-sd command produces no output "records" and also by
disabling unicast DNS access.
I wonder if there has been a change in 10.13 to workaround this problem
as I don't see any delay or external MDNS lookups happening.
.
Could you send me the output of "scutil --dns" of your laptop?
At the same time, I will ask some colleagues here who might be running 10.12
to try it out.
Thanks,
Michael
On 04/04/2019, 18:38, Nora Howard wrote:
> Here's the diff http://cr.openjdk.java.net/~tonyp/8170910/webrev.0/
> <http://cr.openjdk.java.net/%7Etonyp/8170910/webrev.0/>
>
> To setup an env to reproduce the issue, on a OSX machine with >=
> 10.12, turn off services that register with mDNS. For my laptop, I had
> to turn off iTunes and General System Preferences, disable "Allow
> Handoff between this Mac and your iCloud services". You might have to
> restart. The reporter on the ticket said to run `dns-sd -lo -B
> _services._dns-sd._udp local` to see whether you have any running.
>
> The file I used for exercising the behavior looks like this
>
> import java.net.InetAddress;
> public class Test {
> public static void main(String[] args) throws Exception {
> for (int i=0;i<4;i++){
> long start = System.currentTimeMillis();
> InetAddress localHost = InetAddress.getLocalHost();
> System.out.println(localHost);
> System.out.println(System.currentTimeMillis() - start);
> }}}
>
> The output I get on my laptop when I've set things up this way looks
> like this on JDK 13 EA. The first call takes the full 5 seconds and
> subsequent ones hit a cache.
>
> nhoward.local/10.0.0.3 <http://10.0.0.3>
> 5044
> nhoward.local/10.0.0.3 <http://10.0.0.3>
> 0
> nhoward.local/10.0.0.3 <http://10.0.0.3>
> 0
> nhoward.local/10.0.0.3 <http://10.0.0.3>
> 0
>
> On JDK 8, each request takes 5 seconds. JDK 8's address lookup cache
> works differently. It's localhost name cache expiry is 5 seconds.
>
>
>
> On Thu, Apr 4, 2019 at 2:41 AM Michael McMahon
> <michael.x.mcmahon at oracle.com <mailto:michael.x.mcmahon at oracle.com>>
> wrote:
>
> Hi Nora,
>
> At first sight, the approach sounds reasonable to me. I'd like to
> see the patch
> and also do you have detailed instructions on how to reproduce the
> issue (the 5 second delay)?
>
> Thanks,
> Michael.
>
> On 03/04/2019, 17:46, Nora Howard wrote:
>> I'd initially sent this to jdk-dev, but I was asked to move it to
>> net-dev.
>>
>> On OSX 10.12 or later, when no mDNS services are registered,
>> getaddrinfo fails on looking up localhost addresses[1]. The jdk’s
>> current implementation falls back to getifaddrs after getaddrinfo
>> fails[2]. When getaddrinfo fails in this way, it takes 5 seconds
>> to fail [3]. This means that calls to InetAddress.getLocalHost()
>> may take up to 5 seconds to run.
>>
>> I’d like to change the jdk’s behavior in this instance so that
>> instead of falling back to calling getifaddrs after getaddrinfo
>> fails, it instead calls getifaddrs first if we’re on OSX and the
>> hostname is localhost’s.
>>
>> Doing this will eliminate the 5 second delay looking up localhost
>> on machines with this network setup. When looking up
>> non-localhost addresses, it’ll add a call to os:gethostname and a
>> comparison.
>>
>> I’d like to get some feedback about whether this approach sounds
>> reasonable, and some guidance about next steps. I’ve read the
>> “how to contribute” page[4], and the “code review” guide[5].
>>
>> I’ve put together a patch that I’ve tested locally by turning off
>> mDNS services on my local OSX machine and exercising the
>> behavior. I’d like to submit patches that target dev trunk as
>> well as the jdk 8 and 11 branches.
>>
>> References
>>
>> 1.
>>
>> On a Macintosh running 10.12 or later, if there are no apps
>> that have a mDNS services registered (for instance, iTunes)
>> and there are no services selected in the Sharing System
>> Preferences, then the getaddrinfo will fail.
>>
>> (https://bugs.openjdk.java.net/browse/JDK-8170910)
>>
>> 2.
>> http://hg.openjdk.java.net/jdk/jdk/file/cd3b7ad53265/src/java.base/unix/native/libnet/Inet6AddressImpl.c#l252
>> http://hg.openjdk.java.net/jdk/jdk/file/cd3b7ad53265/src/java.base/unix/native/libnet/Inet4AddressImpl.c#l132
>> (The lookupIfLocalhost function checks the passed hostname
>> against os::get_host_name, and if they match, looks up via
>> getifaddrs.)
>>
>> 3. This comment describes how to reproduce the issue. I’ve
>> reproduced it locally on jdk 8, 11 and 13 ea.
>> https://bugs.openjdk.java.net/browse/JDK-8170910?focusedCommentId=14038262&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14038262
>> <https://bugs.openjdk.java.net/browse/JDK-8170910?focusedCommentId=14038262&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14038262>
>>
>> 4. https://openjdk.java.net/contribute/
>>
>> 5. https://openjdk.java.net/guide/codeReview.html
>>
>> Thanks,
>> --
>> Nora
>
>
>
> --
> Nora
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/net-dev/attachments/20190405/567eeaa1/attachment.html>
More information about the net-dev
mailing list