Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dubbo 2.7.14开始在docker swarm中注册到nacos中IP地址出现问题 #9617

Open
zhlking opened this issue Jan 24, 2022 · 3 comments
Open
Labels
type/bug Bugs to being fixed

Comments

@zhlking
Copy link

zhlking commented Jan 24, 2022

Environment

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<InetAddress> addresses = networkInterface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    Optional<InetAddress> 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<InetAddress> addresses = networkInterface.getInetAddresses();
                while (addresses.hasMoreElements()) {
                    Optional<InetAddress> addressOp = toValidAddress(addresses.nextElement());
                    if (addressOp.isPresent()) {
                        try {
                            if (addressOp.get().isReachable(100)) {
                                result = networkInterface;
                                break;
                            }
                        } catch (IOException e) {
                            // ignore
                        }
                    }
                }
            }
        }
@zhlking zhlking added the type/bug Bugs to being fixed label Jan 24, 2022
@zhlking zhlking changed the title 从dubbo 2.7.14在docker swarm中注册到nacos中IP地址出现问题 dubbo 2.7.14开始在docker swarm中注册到nacos中IP地址出现问题 Jan 24, 2022
@FelixLiuSheng
Copy link

我今天在dubbo 3.0.5上也遇到了类似的问题,在docker host模式或者本机正常启动都可能存在ip地址获取不正确的问题,望在下一个版本中得到修复

@Alloyee
Copy link

Alloyee commented Mar 4, 2022

一样的问题,目前通过扩展一个Registory和RegistoryFactory来解决的
`public class Nacos2Registry extends NacosRegistry {
public Nacos2Registry(URL url, NacosNamingServiceWrapper namingService) {
super(url, namingService);
}

@Override
public void register(URL url) {
    log.info("Nacos2Registry register before setting,url:{}",url);
    url = url.setHost(NetUtils.getIpAddress());
    log.info("Nacos2Registry register after setting,url:{}",url);
    super.register(url);
}

@Override
public void unregister(URL url) {
    log.info("Nacos2Registry unregister,url:{}",url);
    url = url.setHost(NetUtils.getIpAddress());
    super.unregister(url);
}

}`
image

@CrazyHZM
Copy link
Member

I think we can extend the way to get the address to adapt to different scenarios.
@chickenlj Do you have any other ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Bugs to being fixed
Projects
None yet
Development

No branches or pull requests

4 participants