Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

child class java.net.InetAddress$NameServiceAddresses for class InetAddress.Addresses should never happens #209

Open
Wackerle opened this issue Dec 1, 2023 · 4 comments

Comments

@Wackerle
Copy link

Wackerle commented Dec 1, 2023

相同的服务运行在多台服务器上,其中有个别服务器偶现报错:

Caused by: java.lang.IllegalStateException: child class java.net.InetAddress$NameServiceAddresses for class InetAddress.Addresses should never happens, report issue for dns-cache-manipulator lib!
	at com.alibaba.dcm.internal.InetAddressCacheUtilForNew.inetAddress$Addresses2DnsCacheEntry(InetAddressCacheUtilForNew.java:243)
	at com.alibaba.dcm.internal.InetAddressCacheUtilForNew.getInetAddressCache(InetAddressCacheUtilForNew.java:203)
	at com.alibaba.dcm.DnsCacheManipulator.getDnsCache(DnsCacheManipulator.java:156)
	... 63 more

版本:1.8.0
环境信息:jdk8,amd

@oldratlee
Copy link
Member

oldratlee commented Jan 22, 2024

@Wackerle 收到。

给一下: ❤️

  • 运行的JDK版本
  • 所用的java-dns-cache-manipulator库版本

@Wackerle
Copy link
Author

jdk 1.8.0_382
java-dns-cache-manipulator 1.8.0

@Wackerle
Copy link
Author

Wackerle commented Feb 22, 2024

复现代码

ExecutorService executorService = Executors.newFixedThreadPool(2);
executorService.execute(() -> {
    try {
        DnsCacheEntry entry = DnsCacheManipulator.getDnsCache("baidu.com");
    } catch (Exception e) {
        e.printStackTrace();
    }
});
executorService.execute(() -> {
    try {
        HttpClient httpClient = HttpClients.custom().build();
        HttpGet httpGet = new HttpGet("http://baidu.com");
        httpClient.execute(httpGet);
    } catch (Exception e) {
        e.printStackTrace();
    }
});
Thread.sleep(100_000);

报错

Caused by: java.lang.IllegalStateException: child class java.net.InetAddress$NameServiceAddresses for class InetAddress.Addresses should never happens, report issue for dns-cache-manipulator lib!
	at com.alibaba.dcm.internal.InetAddressCacheUtilForNew.inetAddress$Addresses2DnsCacheEntry(InetAddressCacheUtilForNew.java:243)
	at com.alibaba.dcm.internal.InetAddressCacheUtilForNew.getInetAddressCache(InetAddressCacheUtilForNew.java:203)
	at com.alibaba.dcm.DnsCacheManipulator.getDnsCache(DnsCacheManipulator.java:156)
	... 4 more

当调用getDnsCache获取域名解析时,同时访问这个域名,会出现这个问题。

原因分析

访问这个域名时,JDK(1.8.0_382)尝试解析这个域名,会先往cache里写入一个NameServiceAddresses,然后委托给NameService解析域名,并将解析结果封装为CachedAddresses替换到cache里。
代码位置:java.net.InetAddress#getAllByName0(java.lang.String, java.net.InetAddress, boolean, boolean)

在没有替换之前,getDnsCache会从cache里获取到NameServiceAddresses,引发报错。
代码位置:com.alibaba.dcm.internal.InetAddressCacheUtilForNew#getInetAddressCache

建议

如果从cache里获取到NameServiceAddresses时,不抛出异常,当做没有域名解析处理。

@oldratlee
Copy link
Member

oldratlee commented Feb 22, 2024

@Wackerle COOOL 👍 我看一下。💕

方便可以开个PR? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants