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

DistroConsistencyServiceImpl的listen/unListen并发场景不安全(1.x) #8434

Closed
liqipeng opened this issue May 22, 2022 · 0 comments
Closed
Milestone

Comments

@liqipeng
Copy link
Contributor

Describe the bug
nacos-server: 1.4.3
com.alibaba.nacos.naming.consistency.ephemeral.distro.DistroConsistencyServiceImpl

    @Override
    public void listen(String key, RecordListener listener) throws NacosException {
        if (!listeners.containsKey(key)) {
            listeners.put(key, new ConcurrentLinkedQueue<>());
        }
        
        if (listeners.get(key).contains(listener)) {
            return;
        }
        
        listeners.get(key).add(listener); // 并发下可能重复
    }
    
    @Override
    public void unListen(String key, RecordListener listener) throws NacosException {
        if (!listeners.containsKey(key)) {
            return;
        }
        for (RecordListener recordListener : listeners.get(key)) { // 并发下可能NPE
            if (recordListener.equals(listener)) {
                listeners.get(key).remove(listener);
                break;
            }
        }
    }
liqipeng added a commit to liqipeng/nacos that referenced this issue May 22, 2022
KomachiSion pushed a commit that referenced this issue May 23, 2022
@KomachiSion KomachiSion added this to the 1.4.4 milestone May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants