dianjifzm
dianjifzm
> Will `InetAddress.getLocalHost()` return null in your environment? 不是 InetAddress.getLocalHost() ,是NetUtils.getLocalAddress() 返回null 这会导致每次调用NetUtils.getLocalHost() 都会再次调用getLocalAddress() 并且触发完整的计算过程 我做了一些尝试。 仅在M2芯片,macOS 14.2.1 (mac mini) 会复现。 普通用户权限会一直返回false,root用户可以正常返回。 在Linux,inter 芯片的Mac,以及windows 11 上,都没有复现。 根本原因是InetAddress.isReachable的native实现有缺陷。 NetUtils中使用了InetAddress.isReachable做了有效性校验,导致了NetUtils.getLocalAddress() 返回null 其实网上吐槽InetAddress.isReachable的帖子有很多,很多人还建议用JNI调用ping的方式,在业务逻辑修复此缺陷...
InetAddress.isReachable 的问题虽然一直存在,但是在 dubbo 3.1.0 之前,NetUtils.getLocalAddress0() 并不会返回null 因为即使InetAddress.isReachable校验不通过,仍然会返回默认值 localAddress = InetAddress.getLocalHost(); 后来代码中加入了IPv6支持 localAddress = getLocalAddressV6(); 导致 默认值逻辑发生变化,默认值不再是InetAddress.getLocalHost() 而是 getLocalAddressV6() 因此性能问题才出现。 我已经提交了修复方案,希望尽快CR https://github.com/apache/dubbo/pull/13745
> Hi @dianjifzm! Can you give more context for what you're trying to do? I [passed the PR description through Google Translate](https://translate.google.com/?sl=auto&tl=en&text=%E5%BC%80%E6%94%BEcommitData%E7%9A%84%E4%BF%AE%E6%94%B9%EF%BC%8C%E5%8F%AF%E4%BB%A5%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5%E7%9A%84%E5%AE%89%E5%85%A8%E6%9C%BA%E5%88%B6&op=translate), but it wasn't enough for me to understand...