Alanxtl commented on code in PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#discussion_r2724939493


##########
registry/nacos/registry.go:
##########
@@ -200,16 +202,23 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, 
notifyListener registry.Noti
 }
 
 func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener 
registry.NotifyListener) {
-       // retry forever
-       for {
+       bo := backoff.NewExponentialBackOff()
+       bo.InitialInterval = 1 * time.Second
+       bo.MaxInterval = 30 * time.Second
+       bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+       operation := func() error {
                if !nr.IsAvailable() {
-                       return
-               }
-               err := nr.subscribe(getSubscribeName(url), notifyListener)
-               if err == nil {
-                       return
+                       return backoff.Permanent(perrors.New("registry 
unavailable"))
                }
+               return nr.subscribe(getSubscribeName(url), notifyListener)
+       }
+
+       notify := func(err error, duration time.Duration) {
+               logger.Warnf("[Nacos Registry] subscribe failed, retry after 
%v: %v", duration, err)
        }
+
+       _ = backoff.RetryNotify(operation, bo, notify)

Review Comment:
   这里如果backoff.RetryNotify失败不需要打日志吗



##########
registry/nacos/registry.go:
##########
@@ -200,16 +202,23 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, 
notifyListener registry.Noti
 }
 
 func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener 
registry.NotifyListener) {
-       // retry forever
-       for {
+       bo := backoff.NewExponentialBackOff()
+       bo.InitialInterval = 1 * time.Second
+       bo.MaxInterval = 30 * time.Second
+       bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+       operation := func() error {
                if !nr.IsAvailable() {
-                       return
-               }
-               err := nr.subscribe(getSubscribeName(url), notifyListener)
-               if err == nil {
-                       return
+                       return backoff.Permanent(perrors.New("registry 
unavailable"))
                }

Review Comment:
   
假如一开始nr.IsAvailable()就失败了,然后进入backoff.Permanent,这样之后是不是就不会再有任何机制进行重试了,这是符合预期的行为吗?



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