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

InetAddress.getAllByName only reports "unknown error" instead of actual cause

    Details

    • Subcomponent:
    • Introduced In Build:
      b15
    • Introduced In Version:
      8
    • Resolved In Build:
      b01
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_51"
        Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
        Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Linux alainodea-xps-l521x 3.13.0-46-generic #79-Ubuntu SMP Tue Mar 10 20:06:50 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

        DISTRIB_ID=Ubuntu
        DISTRIB_RELEASE=14.04
        DISTRIB_CODENAME=trusty
        DISTRIB_DESCRIPTION="Ubuntu 14.04.3 LTS"

        A DESCRIPTION OF THE PROBLEM :
        I think I have identified a regression in network error handling from Java 7 to Java 8.

        In Java 7, attempts to resolve a host unknown to the DNS server cause an UnknownHostException stating "Name or service not known".

        In Java 8, attempts to resolve a host unknown to the DNS server cause an UnknownHostException stating "unknown error".

        Possible root cause:
        It appears that Java 7 had initialization that allowed the gai_strerror_ptr function pointer to be correctly initialized:
        http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/src/solaris/native/java/net/net_util_md.c#l398

        However, I cannot find equivalent initialization in JDK 8:
        http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/solaris/native/java/net/net_util_md.c

        REGRESSION. Last worked in version 7u80

        ADDITIONAL REGRESSION INFORMATION:
        java version "1.7.0_80"
        Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
        Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1. Create a file called InetAddressGetAllByName.java with the content from the source code I have listed on this case

        2. Compile InetAddressGetAllByName.java:
        javac InetAddressGetAllByName.java

        3. Run InetAddressGetAllByName
        java InetAddressGetAllByName

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The following is the

        Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1248)
        at java.net.InetAddress.getAllByName(InetAddress.java:1164)
        at java.net.InetAddress.getAllByName(InetAddress.java:1098)
        at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)
        ACTUAL -
        Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: unknown error
        at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
        at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
        at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
        at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
        at java.net.InetAddress.getAllByName(InetAddress.java:1192)
        at java.net.InetAddress.getAllByName(InetAddress.java:1126)
        at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.net.InetAddress;
        import java.net.UnknownHostException;
        import java.util.Arrays;
        public class InetAddressGetAllByName {
            public static void main(String[] args) throws UnknownHostException {
                System.out.println(Arrays.toString(InetAddress.getAllByName("doesnotexist.example.com")));
            }
        }

        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Use filtered system call tracing to determine actual causes when this happens.

          Issue Links

            Activity

            Hide
            psonal Pallavi Sonal added a comment - - edited
            This issue is reproducible in Linux OS. Attached test case was run on following versions and below are the results:
            JDK 7u80 - Pass
            JDK 8 -Fail
            JDK 8u51- Fail
            JDK 8u60 -Fail
            JDK 8u66 -Fail
            JDK 9ea -Pass

            Following is a snapshot of the results obtained with 7u80 ,8u60 and 9ea versions:
            1.7.0_80
            Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known
                    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
                    at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
                    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)
                    at java.net.InetAddress.getAllByName0(InetAddress.java:1248)
                    at java.net.InetAddress.getAllByName(InetAddress.java:1164)
                    at java.net.InetAddress.getAllByName(InetAddress.java:1098)
                    at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)

            -----------------------------------------------------------------------------
            1.8.0_60
            Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: unknown error
                    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
                    at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
                    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
                    at java.net.InetAddress.getAllByName0(InetAddress.java:1276)
                    at java.net.InetAddress.getAllByName(InetAddress.java:1192)
                    at java.net.InetAddress.getAllByName(InetAddress.java:1126)
                    at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)

            ------------------------------------------------------------------------------

            1.9.0-ea
            Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known
                    at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
                    at java.net.InetAddress$3.lookupAllHostAddr(InetAddress.java:872)
                    at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1288)
                    at java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:821)
                    at java.net.InetAddress.getAllByName0(InetAddress.java:1277)
                    at java.net.InetAddress.getAllByName(InetAddress.java:1136)
                    at java.net.InetAddress.getAllByName(InetAddress.java:1070)
                    at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7)

            Moving to dev-team for further action.
            Show
            psonal Pallavi Sonal added a comment - - edited This issue is reproducible in Linux OS. Attached test case was run on following versions and below are the results: JDK 7u80 - Pass JDK 8 -Fail JDK 8u51- Fail JDK 8u60 -Fail JDK 8u66 -Fail JDK 9ea -Pass Following is a snapshot of the results obtained with 7u80 ,8u60 and 9ea versions: 1.7.0_80 Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known         at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)         at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)         at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1295)         at java.net.InetAddress.getAllByName0(InetAddress.java:1248)         at java.net.InetAddress.getAllByName(InetAddress.java:1164)         at java.net.InetAddress.getAllByName(InetAddress.java:1098)         at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7) ----------------------------------------------------------------------------- 1.8.0_60 Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: unknown error         at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)         at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)         at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)         at java.net.InetAddress.getAllByName0(InetAddress.java:1276)         at java.net.InetAddress.getAllByName(InetAddress.java:1192)         at java.net.InetAddress.getAllByName(InetAddress.java:1126)         at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7) ------------------------------------------------------------------------------ 1.9.0-ea Exception in thread "main" java.net.UnknownHostException: doesnotexist.example.com: Name or service not known         at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)         at java.net.InetAddress$3.lookupAllHostAddr(InetAddress.java:872)         at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1288)         at java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:821)         at java.net.InetAddress.getAllByName0(InetAddress.java:1277)         at java.net.InetAddress.getAllByName(InetAddress.java:1136)         at java.net.InetAddress.getAllByName(InetAddress.java:1070)         at InetAddressGetAllByName.main(InetAddressGetAllByName.java:7) Moving to dev-team for further action.
            Hide
            rpatil Ramanand Patil added a comment -
            The issue was because of the native code changes in net_util_md.c for Solaris platform.

            Brief History:
            1. As per the jdk7 bug JDK-6981157: An improvement was added to UnknownHostException which was integrated into jdk7-ea-b114.
            Bug: https://bugs.openjdk.java.net/browse/JDK-6981157
            6981157: Improve UnknownHostException with EAI error details and other cleanups.

            2. Later in jdk8 as per the bug JDK-7112670: Inet4AddressImpl.c implementation was changed to be consistent with Inet6AddressImpl.c (like using getaddrinfo instead of gethostbyname).
            While doing this author has removed few function pointers present in net.util.md.c since he used functions directly. While doing this the function pointer defined for getaddressinfo error namely - gai_strerror_ptr was also removed which was actually providing the actual error information. That time no issue was found because the variable declarations were not removed for any of the removed function pointer variables. This patch was integrated into jdk8-ea-b15.
            The corresponding bug is: https://bugs.openjdk.java.net/browse/JDK-7112670
            7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo ( modernization/cleanup )

            We should actually remove all the unused variable declarations from net.util.md.c and net.util.md.
            In UnknownHostException the 'gai_strerror_ptr' check should be replaced with the direct method call.
            i.e. :const char *error_string = gai_strerror(gai_error);
            Show
            rpatil Ramanand Patil added a comment - The issue was because of the native code changes in net_util_md.c for Solaris platform. Brief History: 1. As per the jdk7 bug JDK-6981157 : An improvement was added to UnknownHostException which was integrated into jdk7-ea-b114. Bug: https://bugs.openjdk.java.net/browse/JDK-6981157 6981157: Improve UnknownHostException with EAI error details and other cleanups. 2. Later in jdk8 as per the bug JDK-7112670 : Inet4AddressImpl.c implementation was changed to be consistent with Inet6AddressImpl.c (like using getaddrinfo instead of gethostbyname). While doing this author has removed few function pointers present in net.util.md.c since he used functions directly. While doing this the function pointer defined for getaddressinfo error namely - gai_strerror_ptr was also removed which was actually providing the actual error information. That time no issue was found because the variable declarations were not removed for any of the removed function pointer variables. This patch was integrated into jdk8-ea-b15. The corresponding bug is: https://bugs.openjdk.java.net/browse/JDK-7112670 7112670: Inet4AddressImpl should use getaddrinfo/getnameinfo ( modernization/cleanup ) We should actually remove all the unused variable declarations from net.util.md.c and net.util.md. In UnknownHostException the 'gai_strerror_ptr' check should be replaced with the direct method call. i.e. :const char *error_string = gai_strerror(gai_error);
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/rev/aa919ce9e3b6
            User: igerasim
            Date: 2016-02-17 12:07:07 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8u/jdk8u-dev/jdk/rev/aa919ce9e3b6 User: igerasim Date: 2016-02-17 12:07:07 +0000
            Hide
            hgupdate HG Updates added a comment -
            URL: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/aa919ce9e3b6
            User: robm
            Date: 2016-03-01 00:25:04 +0000
            Show
            hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8u/jdk8u/jdk/rev/aa919ce9e3b6 User: robm Date: 2016-03-01 00:25:04 +0000

              People

              • Assignee:
                rpatil Ramanand Patil
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: