nanjiek commented on code in PR #3134:
URL: https://github.com/apache/dubbo-go/pull/3134#discussion_r2648933186


##########
config_center/file/listener.go:
##########
@@ -147,10 +165,17 @@ func (cl *CacheListener) RemoveListener(key string, 
listener config_center.Confi
        if !loaded {
                return
        }
-       delete(listeners.(map[config_center.ConfigurationListener]struct{}), 
listener)
-       if err := cl.watch.Remove(key); err != nil {
-               logger.Errorf("watcher remove path:%s err:%v", key, err)
+       lmap := listeners.(map[config_center.ConfigurationListener]struct{})
+       delete(lmap, listener)
+       if len(lmap) == 0 {
+               cl.keyListeners.Delete(key)
+               cl.contentCache.Delete(key)
+               if err := cl.watch.Remove(key); err != nil {
+                       logger.Errorf("watcher remove path:%s err:%v", key, err)
+               }
+               return
        }
+       cl.keyListeners.Store(key, lmap)
 }

Review Comment:
   > Concurrency is not safe here; consider whether problems might arise.
   
   目前解决的是同一个 key 还有订阅者时提前解除 watcher,导致后续事件收不到的问题。在实际场景里,config_center 的 
listener 注册/移除都是初始化和关闭阶段的串行调用,同一 key 不会并发 Add/Remove,因此现状不会触发竞争。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to