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

JDNI fails to resolve SRV entries when IPV6 stack is enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 16
    • core-libs
    • None
    • Windows 10 21H1
      Minecraft 1.17.1, Bundled Java 16 (issue persists on AdoptOpenJDK HotSpot 16)

      Background:

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

      They 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, while it’s just 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-8232817 + 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.

            Unassigned Unassigned
            macarte Mat Carter
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: