Giter Site home page Giter Site logo

child class java.net.InetAddress$NameServiceAddresses for class InetAddress.Addresses should never happens about java-dns-cache-manipulator HOT 4 OPEN

Wackerle avatar Wackerle commented on June 8, 2024 2
child class java.net.InetAddress$NameServiceAddresses for class InetAddress.Addresses should never happens

from java-dns-cache-manipulator.

Comments (4)

Wackerle avatar Wackerle commented on June 8, 2024 3

复现代码

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.

oldratlee avatar oldratlee commented on June 8, 2024

@Wackerle 收到。

给一下: ❤️

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

from java-dns-cache-manipulator.

Wackerle avatar Wackerle commented on June 8, 2024

jdk 1.8.0_382
java-dns-cache-manipulator 1.8.0

from java-dns-cache-manipulator.

oldratlee avatar oldratlee commented on June 8, 2024

@Wackerle COOOL 👍 我看一下。💕

方便可以开个PR? 😄

from java-dns-cache-manipulator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.