Comments (4)
复现代码
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
时,不抛出异常,当做没有域名解析处理。
from java-dns-cache-manipulator.
@Wackerle 收到。
给一下: ❤️
- 运行的
JDK
版本 - 所用的
java-dns-cache-manipulator
库版本
from java-dns-cache-manipulator.
jdk 1.8.0_382
java-dns-cache-manipulator 1.8.0
from java-dns-cache-manipulator.
@Wackerle COOOL 👍 我看一下。💕
方便可以开个PR? 😄
from java-dns-cache-manipulator.
Related Issues (20)
- Support config file name setting by -D option
- use specification test framework(BDD) rewrite unit test HOT 1
- 使用SSM整合HttpClient,使用工具包设置DNS,打印出来的DNS为最新的,但是请求时调用的DNS为缓存的设置 HOT 3
- 多个jvm进程怎么共享一个dns?
- how to share dns in all jvm process? HOT 1
- Support JDK 11 HOT 10
- 可以使用这个开发成1个dns服务器 HOT 1
- 什么时候可以支持 JKD 11 呢 HOT 2
- Fix "argument_count" issue in tool/src/main/java/com/alibaba/dcm/tool/DcmTool.java
- Fix "similar-code" issue in library/src/main/java/com/alibaba/dcm/agent/DcmAgent.java
- Fix "identical-code" issue in library/src/main/java/com/alibaba/dcm/internal/InetAddressCacheUtilForJava8Minus.java
- Fix initFieldsOfInetAddressCachePolicy method issue in library/src/main/java/com/alibaba/dcm/internal/InetAddressCacheUtilCommons.java
- Fix "method_complexity" issue in library/src/main/java/com/alibaba/dcm/internal/InetAddressCacheUtilForJava8Minus.java
- Fix Method inetAddress$Addresses2DnsCacheEntry issue in InetAddressCacheUtilForJava9Plus
- Fix "squid:S00112" issue in library/src/main/java/com/alibaba/dcm/agent/DcmAgent.java
- jdk11支持吗
- Issue on GitHub Actions with latest Zulu 8u352 JDK HOT 7
- Caused by: java.lang.ClassNotFoundException: java.net.InetAddress$CachedAddresses HOT 5
- Support for JDK 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-dns-cache-manipulator.