dubbo 2.7.14开始在docker swarm中注册到nacos中IP地址出现问题
- Dominant language
- Java
- Stars
- 41.6k
- Forks
- 26.4k
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 4
Description
### Environment
* docker swarm
* Dubbo version: 2.7.14
* Java version: 1.8
* #8679 这个更新后开始出现问题的
docker swarm环境下从2.7.14版本开始获取的是本地虚拟网桥段的地址,获取的IP地址只能够在宿主机上访问,跨主机是不能访问的。2.7.14版本之前能获取到容器swarm网络的IP。
暂时解决办法,重写了org.apache.dubbo.common.utils.NetUtils类。
修改dubbo/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java 的428-444行,如下:
```
if (result == null) { // If not found, try to get the first one
for (NetworkInterface networkInterface : validNetworkInterfaces) {
Enumeration addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
Optional addressOp = toValidAddress(addresses.nextElement());
if (addressOp.isPresent()) {
try {
if (addressOp.get().isReachable(100)) {
return networkInterface;
}
} catch (IOException e) {
// ignore
}
}
}
}
}
```
改为:
```
if (result == null) { // If not found, try to get the first one
for (NetworkInterface networkInterface : validNetworkInterfaces) {
Enumeration addresses = networkInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
Optional addressOp = toValidAddress(addresses.nextElement());
if (addressOp.isPresent()) {
try {
if (addressOp.get().isReachable(100)) {
result = networkInterface;
break;
}
} catch (IOException e) {
// ignore
}
}
}
}
}
```
Contributor guide
Research direction
Start with dubbo/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java, especially lines 428-444 and the interface-selection logic changed after #8679. Reproduce the address selection in a Docker Swarm environment and compare it with Dubbo 2.7.14 and an earlier version. Done means registration uses an address reachable across Swarm hosts rather than only the host-local virtual bridge address.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java
- Domain
- distributed-systems, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100