AlexStocks commented on code in PR #3387:
URL: https://github.com/apache/dubbo-go/pull/3387#discussion_r3407816807


##########
registry/etcdv3/registry.go:
##########
@@ -158,14 +195,41 @@ func (r *etcdV3Registry) DoSubscribe(svc *common.URL) 
(registry.Listener, error)
        }
 
        // register the svc to dataListener
-       r.dataListener.AddInterestedURL(svc)
-       go 
r.listener.ListenServiceEvent(fmt.Sprintf("/dubbo/%s/"+constant.DefaultCategory,
 svc.Service()), r.dataListener)
+       configListener := NewConfigurationListener(r, svc)
+       r.dataListener.subscribeURLLocked(svc, configListener)
+       go listenServiceEvent(r.listener, etcdProviderPath(svc), r.dataListener)
 
        return configListener, nil
 }
 
 func (r *etcdV3Registry) DoUnsubscribe(conf *common.URL) (registry.Listener, 
error) {
-       return nil, perrors.New("DoUnsubscribe is not support in 
etcdV3Registry")
+       if r.dataListener == nil {
+               return nil, perrors.New("etcd data listener is nil, can not 
close")
+       }
+       r.dataListener.mutex.Lock()
+       subscribedListener := r.dataListener.subscribed[conf.ServiceKey()]
+       if subscribedListener != nil {
+               etcdListener, _ := subscribedListener.(*configurationListener)
+               if etcdListener != nil && etcdListener.closed() {
+                       r.dataListener.mutex.Unlock()
+                       return nil, perrors.Errorf("configListener for service 
%s has already been closed", conf.ServiceKey())
+               }
+       }
+       listener := r.dataListener.unsubscribeURLLocked(conf)

Review Comment:
   [P1] 这里在校验 `r.listener == nil` 之前已经调用 `unsubscribeURLLocked`,该调用会关闭 listener 
并从 `subscribed` 中删除记录。若下面返回 `etcd event listener is 
nil`,`BaseRegistry.UnSubscribe` 会把本次退订视为失败,但本地订阅已经被永久移除,后续恢复或重试都拿不到原 
listener。请先完成 `r.listener`/类型校验,再执行关闭和删除,或在错误路径回滚订阅 map。



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