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


##########
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:
   只有 map 为空(即最后一个 listener 被移除)时才调用 watch.Remove(key) 并清理缓存;否则 watcher 
继续监听,其他同 key 的 listener 仍在订阅,不会失去后续事件。



-- 
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