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

在同一个进程的多个NamingService的发布-订阅没有相互隔离 #8428

Closed
liqipeng opened this issue May 22, 2022 · 3 comments
Closed
Labels
area/Client Related to Nacos Client SDK kind/enhancement Category issues or prs related to enhancement.
Milestone

Comments

@liqipeng
Copy link
Contributor

Describe the bug
nacos-client版本:1.4.3
在使用Dubbo框架进行注册中心迁移处理从一个nacos-server迁移至另一个nacos-server时,服务的消费方采用了双订阅的方式进行迁移,但是在迁移的过程中两个Registry会相互影响。
分析发现由于nacos-client的事件通知在不同NamingService实例之间没有隔离,如下场景的两个订阅会相互影响:

String serviceName = "serviceName1";
NamingService namingService1 = NamingFactory.createNamingService("nacos-server1");
NamingService namingService2 = NamingFactory.createNamingService("nacos-server2");

namingService1.subscribe(serviceName, new EventListener() {
    @Override
    public void onEvent(Event event) {

    }
});
namingService2.subscribe(serviceName, new EventListener() {
    @Override
    public void onEvent(Event event) {

    }
});
// 当两个server任意一边有通知时,这两个订阅都会收到通知

nacos-client源码:

    public HostReactor(NamingProxy serverProxy, BeatReactor beatReactor, String cacheDir, boolean loadCacheAtStart,
            boolean pushEmptyProtection, int pollingThreadCount) {
        // ..........
        NotifyCenter.registerToPublisher(InstancesChangeEvent.class, 16384);
        NotifyCenter.registerSubscriber(notifier);
    }

可以看到HostReactor里的发布订阅并没有处理不同 HostReactor 的隔离。

@liqipeng
Copy link
Contributor Author

liqipeng commented May 22, 2022

bug复现:(详见测试subscribeSameServiceForTwoNamingService : liqipeng@64dc1de

        naming1.subscribe(serviceName, new EventListener() {
            @Override
            public void onEvent(Event event) {
                System.out.println("Event from naming1: " + ((NamingEvent) event).getServiceName());
                System.out.println("Event from naming1: " + ((NamingEvent) event).getInstances());
                instances = ((NamingEvent) event).getInstances();
            }
        });
        naming2.subscribe(serviceName, new EventListener() {
            @Override
            public void onEvent(Event event) {
                System.out.println("Event from naming2: " + ((NamingEvent) event).getServiceName());
                System.out.println("Event from naming2: " + ((NamingEvent) event).getInstances());
                atomicInteger.incrementAndGet();
            }
        });
    
        naming1.registerInstance(serviceName, "1.1.1.1", TEST_PORT, "c1");

输出日志:

Event from naming1: DEFAULT_GROUP@@jinhanT06Yu.eRoX3.net
Event from naming1: [Instance{instanceId='1.1.1.1#8080#c1#DEFAULT_GROUP@@jinhanT06Yu.eRoX3.net', ip='1.1.1.1', port=8080, weight=1.0, healthy=true, enabled=true, ephemeral=true, clusterName='c1', serviceName='DEFAULT_GROUP@@jinhanT06Yu.eRoX3.net', metadata={}}]
Event from naming2: DEFAULT_GROUP@@jinhanT06Yu.eRoX3.net
Event from naming2: [Instance{instanceId='1.1.1.1#8080#c1#DEFAULT_GROUP@@jinhanT06Yu.eRoX3.net', ip='1.1.1.1', port=8080, weight=1.0, healthy=true, enabled=true, ephemeral=true, clusterName='c1', serviceName='DEFAULT_GROUP@@jinhanT06Yu.eRoX3.net', metadata={}}]

通过日志可以看到,只有一个变更,但是两个NamingService都接收到了变更事件。

@KomachiSion
Copy link
Collaborator

Should we add an UUID to identity one Client(NamingService) ?

@liqipeng
Copy link
Contributor Author

Should we add an UUID to identity one Client(NamingService) ?

#8433 进行了说明。

liqipeng added a commit to liqipeng/nacos that referenced this issue May 23, 2022
liqipeng added a commit to liqipeng/nacos that referenced this issue May 23, 2022
@KomachiSion KomachiSion added this to the 2.1.1 milestone May 27, 2022
@KomachiSion KomachiSion added kind/enhancement Category issues or prs related to enhancement. area/Client Related to Nacos Client SDK and removed kind/discussion Category issues related to discussion labels May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/Client Related to Nacos Client SDK kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants