You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/06/22 08:57:41 UTC

[dubbo] branch master updated: Fix service was offline without re-registration due to network jitter (#10182)

This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new d6460f53c6 Fix service was offline without re-registration due to network jitter (#10182)
d6460f53c6 is described below

commit d6460f53c663d8f2ce1f7ab887f6987fc6a36a48
Author: 一个不知名的Java靓仔 <cl...@gmail.com>
AuthorDate: Wed Jun 22 16:57:34 2022 +0800

    Fix service was offline without re-registration due to network jitter (#10182)
---
 .../zookeeper/curator/CuratorZookeeperClient.java  | 24 +++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
index 30595f9dbb..5f5931a63e 100644
--- a/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
+++ b/dubbo-remoting/dubbo-remoting-zookeeper/src/main/java/org/apache/dubbo/remoting/zookeeper/curator/CuratorZookeeperClient.java
@@ -46,6 +46,9 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 
 import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
@@ -296,6 +299,15 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
 
     static class CuratorWatcherImpl implements CuratorWatcher {
 
+        private static final ExecutorService CURATOR_WATCHER_EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(new ThreadFactory() {
+            @Override
+            public Thread newThread(Runnable r) {
+                Thread thread = new Thread(r);
+                thread.setName("Dubbo-CuratorWatcher-Thread");
+                return thread;
+            }
+        });
+
         private CuratorFramework client;
         private volatile ChildListener childListener;
         private String path;
@@ -322,7 +334,17 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorZooke
             }
 
             if (childListener != null) {
-                childListener.childChanged(path, client.getChildren().usingWatcher(this).forPath(path));
+                Runnable task = new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            childListener.childChanged(path, client.getChildren().usingWatcher(CuratorWatcherImpl.this).forPath(path));
+                        } catch (Exception e) {
+                            logger.warn("client get children error", e);
+                        }
+                    }
+                };
+                CURATOR_WATCHER_EXECUTOR_SERVICE.execute(task);
             }
         }
     }