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 2021/09/21 16:07:14 UTC
[dubbo] branch master updated: [2.7.x] Fix CountDownLatch not being
released(#8845) (#8862)
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 db17589 [2.7.x] Fix CountDownLatch not being released(#8845) (#8862)
db17589 is described below
commit db175899d73966f52bbd1a9043503ca749a107e8
Author: candy <35...@users.noreply.github.com>
AuthorDate: Wed Sep 22 00:06:31 2021 +0800
[2.7.x] Fix CountDownLatch not being released(#8845) (#8862)
---
.../registry/zookeeper/ZookeeperRegistry.java | 31 ++++++++++++----------
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
index 9686eff..f57d138 100644
--- a/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
+++ b/dubbo-registry/dubbo-registry-zookeeper/src/main/java/org/apache/dubbo/registry/zookeeper/ZookeeperRegistry.java
@@ -165,22 +165,25 @@ public class ZookeeperRegistry extends FailbackRegistry {
}
} else {
CountDownLatch latch = new CountDownLatch(1);
- List<URL> urls = new ArrayList<>();
- for (String path : toCategoriesPath(url)) {
- ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.computeIfAbsent(url, k -> new ConcurrentHashMap<>());
- ChildListener zkListener = listeners.computeIfAbsent(listener, k -> new RegistryChildListenerImpl(url, k, latch));
- if (zkListener instanceof RegistryChildListenerImpl) {
- ((RegistryChildListenerImpl) zkListener).setLatch(latch);
- }
- zkClient.create(path, false);
- List<String> children = zkClient.addChildListener(path, zkListener);
- if (children != null) {
- urls.addAll(toUrlsWithEmpty(url, path, children));
+ try {
+ List<URL> urls = new ArrayList<>();
+ for (String path : toCategoriesPath(url)) {
+ ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.computeIfAbsent(url, k -> new ConcurrentHashMap<>());
+ ChildListener zkListener = listeners.computeIfAbsent(listener, k -> new RegistryChildListenerImpl(url, k, latch));
+ if (zkListener instanceof RegistryChildListenerImpl) {
+ ((RegistryChildListenerImpl) zkListener).setLatch(latch);
+ }
+ zkClient.create(path, false);
+ List<String> children = zkClient.addChildListener(path, zkListener);
+ if (children != null) {
+ urls.addAll(toUrlsWithEmpty(url, path, children));
+ }
}
+ notify(url, listener, urls);
+ } finally {
+ // tells the listener to run only after the sync notification of main thread finishes.
+ latch.countDown();
}
- notify(url, listener, urls);
- // tells the listener to run only after the sync notification of main thread finishes.
- latch.countDown();
}
} catch (Throwable e) {
throw new RpcException("Failed to subscribe " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);