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+nacos服务发现bug(2.7.4.1依然存在) #4793

Closed
supercocoa opened this issue Aug 11, 2019 · 6 comments · Fixed by #4802
Closed

dubbo+nacos服务发现bug(2.7.4.1依然存在) #4793

supercocoa opened this issue Aug 11, 2019 · 6 comments · Fixed by #4802
Milestone

Comments

@supercocoa
Copy link

Environment

  • Dubbo version: 2.7.3 + nacos 1.1.0
  • Operating System version: linux/mac
  • Java version: 1.8

Steps to reproduce this issue

  1. 根据文档通过代码使用dubbo
  2. 在机器X启动A服务provider
  3. 在机器X启动consumerA1,timeout参数为3000,目标是服务A
  4. 在step3的同一进程启动consumerA2,timeout参数为8000,目标也是服务A
  5. 下线机器X的A服务provider,上线机器Y的A服务provider
  6. 通过consumerA2调用服务A还是去已近下线的机器X的A服务provider,连不通,即没有感知到服务上下线,没有去连机器Y的服务Aprovider

debug调试源码发现是NacosRegistrysubscribeEventListener会校验serviceName,同一serviceName只能往NamingService/EventDispatcher注册订阅一个lisnter(consumer),虽然EventDispatcher本身可以一个key加多个listener,看看NacosRegistry是不是这块是不是有bug

//NacosRegistry.java
    private void subscribeEventListener(String serviceName, final URL url, final NotifyListener listener)
            throws NacosException {
        if (!nacosListeners.containsKey(serviceName)) {
            EventListener eventListener = event -> {
                if (event instanceof NamingEvent) {
                    NamingEvent e = (NamingEvent) event;
                    notifySubscriber(url, listener, e.getInstances());
                }
            };
            namingService.subscribe(serviceName, eventListener);
            nacosListeners.put(serviceName, eventListener);
        }
    }
//EventDispatcher.java
    public void addListener(ServiceInfo serviceInfo, String clusters, EventListener listener) {

        NAMING_LOGGER.info("[LISTENER] adding " + serviceInfo.getName() + " with " + clusters + " to listener map");
        List<EventListener> observers = Collections.synchronizedList(new ArrayList<EventListener>());
        observers.add(listener);

        observers = observerMap.putIfAbsent(ServiceInfo.getKey(serviceInfo.getName(), clusters), observers);
        if (observers != null) {
            observers.add(listener);
        }

        serviceChanged(serviceInfo);
    }

Expected Result

consumerA2可以连接到正确机器Y的A服务provider

Actual Result

consumerA2可以连接到下线机器X的A服务provider

@tswstarplanet
Copy link
Contributor

tswstarplanet commented Aug 12, 2019

你下线提供者是在nacos把配置删除,还是直接把那个提供者进程关掉啊?

@supercocoa
Copy link
Author

关掉provider进程 @tswstarplanet

@tswstarplanet
Copy link
Contributor

I have found the reason. I will submit a pr to fix it.

@cvictory
Copy link
Contributor

cvictory commented Sep 4, 2019

#4802

@supercocoa supercocoa changed the title dubbo+nacos服务发现bug dubbo+nacos服务发现bug(2.7.4.1依然存在) Nov 15, 2019
@supercocoa
Copy link
Author

换了2.7.4.1问题依然存在 @tswstarplanet @beiwei30

@webeasymail
Copy link

dubbo 2.7.8 依然存在这个问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants