You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/04 13:19:17 UTC

[GitHub] [dubbo] zrlw opened a new issue #8676: [3.0] 获取本机地址的方法可能需要统一

zrlw opened a new issue #8676:
URL: https://github.com/apache/dubbo/issues/8676


   ### Environment
   
   * Dubbo version: 3.0 (2.7.x也有此类问题)
   
   本机环境安装了Virtualbox虚拟机,所以有多个virtualbox host-only网卡,这些网卡属性和普通网卡没区别,isVirtual同样返回false,isUp同样返回true。
   本机编译测试3.0的代码,跑mvn test不管有没有其他单元测试错误,ReferenceAnnotationBeanPostProcessorTest这个测试类的testAop一直是下面这种结果:
   ```
   ReferenceAnnotationBeanPostProcessorTest.testAop:160 expected: <Hello, Mercy(based on AOP) from 192.168.99.1:12345> but was: <Hello, Mercy(based on AOP) from 192.168.xx.yy:12345>
   ```
   expected的地址192.168.99.1这个不会变,后面那个192.168.xx.yy地址不太固定,本着好奇的心态跟踪了一下,看看这个测试到底在搞什么鬼,结果发现两处不那么正常的地方:
   1. org.apache.dubbo.common.utils.NetUtils工具类获取本机地址时调用findNetworkInterface的代码看起来有手误,没有及时结束循环,拿了最后一个reachable网卡地址交差了,不管是windows还是linux,多网卡环境下interfaces数组里面的第一块网卡通常是实际的物理网卡,后面的可能就是虚拟的呵呵了。
   2. ServiceConfig先判断有没有地址参数配置,没有就自己用java.net.InetAddress的getLocalHost获取本机地址,这个方法跟了一下跟到了native,不清楚实际处理逻辑,总之取到的地址和NetUtils取的不一样,每次调用它返回的结果还不一定和之前一样,几个本机地址都可能返回。
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zrlw commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-1018079832


   修改后的NetUtils.java的findNetworkInterface返回的是第一个可用的网卡,也就是权重最高的网卡,只是你们恰好是本地虚拟网桥段地址,之前的代码忘了break循环,所以取了最后一个可用的网卡,在虚拟机等大多数环境下最后一个网卡权重最小,使用出问题的概率最大,这个问题没有办法兼顾,否则也不会搞个-DDUBBO_IP_TO_BIND启动参数指定ip地址了,我个人认为获取本地地址还是取权重最大的网卡较为合适,只是你们的情况比较特殊,恰好要使用权重最小的网卡。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zrlw commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-1018211250


   hostname确认机器名,在/etc/hosts加一条与之对应的ip地址应该也可以,这种方法可能也算不上方便。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] CrazyHZM closed issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
CrazyHZM closed issue #8676:
URL: https://github.com/apache/dubbo/issues/8676


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] techa03 commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
techa03 commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-1018139322


   > 复杂网络环境下建议在启动脚本设置 -DDUBBO_IP_TO_BIND=x.x.x.x的方式,自动获取本地地址的方法无论怎么搞都不可能解决所有的场景。
   
   docker-swarm集群ip地址不固定,这种设置-DDUBBO_IP_TO_BIND=x.x.x.x的方式不太方便,有更好的办法吗?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zrlw edited a comment on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zrlw edited a comment on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-913015702


   MetricsFilter这个类的getUrl调用NetUtils.getIpByConfig获取地址,如果没有配置DUBBO_IP_TO_BIND参数就取本机地址,然后又按地址名称取IP,本来取本机地址就取到了物理网卡地址了,结果按物理网卡地址对应的网络名又取了一次IP,因为同名的网卡有多个,排第一的是一个virtualbox host-only地址,InetAddress就取头一个返回,搞得MetricsFilterTest测试不通过。
   用户不配置,像MetricsFilterTest测试类做的那样简单取一下NetUtils.getLocalHost()应该就行了,考虑得太多,超过实际需要之后结果就离谱了。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zrlw commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-1018220066


   调整interface的metric应该也算一个方法,把想要的interface的metric设置为最小(优先级最高),route -n查看metric,ifmetric interface metric-value指定网络接口的metric值。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zrlw commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-913015702


   MetricsFilter这个类的getUrl调用NetUtils.getIpByConfig获取地址,如果没有配置DUBBO_IP_TO_BIND参数就取本机地址,然后又按地址名称取IP,本来取本机地址就取到了物理网卡地址了,结果按物理网卡地址对应的网络名又取了一次IP,因为同名的网卡有多个,排第一的是一个virtualbox host-only地址,然后就搞得MetricsFilterTest测试类失败。
   用户不配置,像MetricsFilterTest测试类做的那样简单取一下NetUtils.getLocalHost()应该就行了,考虑得太多,超过实际需要之后结果就离谱了。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zhlking commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zhlking commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-1017068109


   我们使用的docker swam集群,2.7.14版本之前能获取到容器swarm网络的IP,现在获取的是本地虚拟网桥段的地址,这个IP地址只能够本机访问,跨主机是不能访问的。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org


[GitHub] [dubbo] zrlw commented on issue #8676: 获取本机地址的方法可能需要统一

Posted by GitBox <gi...@apache.org>.
zrlw commented on issue #8676:
URL: https://github.com/apache/dubbo/issues/8676#issuecomment-1018080617


   复杂网络环境下建议在启动脚本设置 -DDUBBO_IP_TO_BIND=x.x.x.x的方式,自动获取本地地址的方法无论怎么搞都不可能解决所有的场景。


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org