JDK-8135259 : InetAddress.getAllByName only reports "unknown error" instead of actual cause

https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8135259

JDK-8135259 : InetAddress.getAllByName only reports "unknown error" instead of actual cause
Type: Bug
Component: core-libs
Sub-Component: java.net
Affected Version: 8
Priority: P3
Status: Resolved
Resolution: Fixed
OS: linux_ubuntu
CPU: x86_64
Submitted: 2015-09-02
Updated: 2016-07-21
Resolved: 2016-02-17
Versions (Unresolved/Resolved/Fixed)

JDK 8
8u102 b01Fixed
Related Reports
Relates :
JDK-7112670 - Inet4AddressImpl should use getaddrinfo/getnameinfo ( modernization/cleanup )
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.InetAddress1.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.InetAddress2.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.

Comments
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);
05-02-2016
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.InetAddress3.lookupAllHostAddr(InetAddress.java:872) at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1288) at java.net.InetAddressNameServiceAddresses.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.

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 196,099评论 5 462
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 82,473评论 2 373
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 143,229评论 0 325
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,570评论 1 267
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,427评论 5 358
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,335评论 1 273
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,737评论 3 386
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,392评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,693评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,730评论 2 312
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,512评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,349评论 3 314
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,750评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,017评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,290评论 1 251
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,706评论 2 342
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,904评论 2 335

推荐阅读更多精彩内容