Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8272996

JNDI DNS provider fails to resolve SRV entries when IPV6 stack is enabled

    XMLWordPrintable

Details

    • b09
    • windows_10

    Backports

      Description

        Background:
        Minecraft is using JNDI to resolve SRV entries from DNS when connecting to server (code below).

        We have recently received a report about this functionality not working (https://bugs.mojang.com/browse/MC-232009) and it seems that following steps are required to reproduce:
        · User is on Windows
        · IPv6 stack enabled, but no connectivity
        · At least one DNSv6 server is configured

        The original report mentions this happening only with non-default ports. In fact it’s due to that specific server configuration (redirect pointing to the same host, but different port)

        Simplified code:

        Hashtable<String, String> env = new Hashtable<>();
        env.put("java.naming.factory.initial", "com.sun.jndi.dns.DnsContextFactory");
        env.put("java.naming.provider.url", "dns:");
        env.put("com.sun.jndi.dns.timeout.retries", "1");
        DirContext context = new InitialDirContext(env);
        Attributes attributes = context.getAttributes("_minecraft._tcp." + host, new String[]{"SRV"});
        Attribute srvAttribute = attributes.get("srv");

        Problem:
        SRV resolver is always throwing java.io.UncheckedIOException: java.net.SocketException: Network is unreachable: connect, even if there are also valid IPv4 DNS servers configured.

        Analysis:
        · JDK internals changed in 15 (JDK-7006496) to now also return IPv6 DNS entries (and usually they are listed before v4 entries)
        · Datagram socket started throwing UncheckedIOException on connection failure (JDK-8232673 + JDK-8235783) - https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/sun/nio/ch/DatagramSocketAdaptor.java#L120
        · During DNS query (https://github.com/openjdk/jdk/blob/master/src/jdk.naming.dns/share/classes/com/sun/jndi/dns/DnsClient.java#L171-L319) method is supposed to check all servers and ignore failed ones (see doNotRetry variable), but only handles few exception types and not the one thrown from `doUdpQuery` call on line 214.

        Attachments

          Issue Links

            Activity

              People

                aefimov Aleksej Efimov
                macarte Mat Carter
                Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: