Consumer cannot get provider instance list updated using Zookeeper registry
- [*] I have searched the issues of this repository and believe that this is not a duplicate.
- [*] I have checked the FAQ of this repository and believe that this is not a duplicate.
Environment
- Dubbo version: 2.7.10
- Operating System version: CentOS 7
- Java version: 1.8.0
Expected Result
Consumer using Zookeeper registry can get provider instance list updated whenever a provider instance is registered or deregistered.
Actual Result
Provider instance list is never updated when first call to doSubscribe failed with an exception.
thread dump below shows that zookeeper event thread is forever waiting on a CountDownLatch.
"main-EventThread" #109 daemon prio=5 os_prio=0 tid=0x00007f5d67934800 nid=0x95 waiting on condition [0x00007f5b41c5e000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000005c73a9390> (a java.util.concurrent.CountDownLatch$Sync)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304)
at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231)
at org.apache.dubbo.registry.zookeeper.ZookeeperRegistry$RegistryChildListenerImpl.childChanged(ZookeeperRegistry.java:338)
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient$CuratorWatcherImpl.process(CuratorZookeeperClient.java:294)
at org.apache.curator.framework.imps.NamespaceWatcher.process(NamespaceWatcher.java:83)
at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:531)
at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:506)
The CountDownLatch is used in ZookeeperRegistry#doSubscribe(), which may not be countDown if an exception is thrown, like below
...
Caused by: org.apache.dubbo.rpc.RpcException: Failed to subscribe consumer://172.17.0.5/..., cause: null
at org.apache.dubbo.registry.zookeeper.ZookeeperRegistry.doSubscribe(ZookeeperRegistry.java:186) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:299) ~[dubbo-2.7.10.jar!/:2.7.10]
... 33 more
Caused by: java.lang.IllegalStateException
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.addTargetChildListener(CuratorZookeeperClient.java:215) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.addTargetChildListener(CuratorZookeeperClient.java:53) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.addChildListener(AbstractZookeeperClient.java:112) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.registry.zookeeper.ZookeeperRegistry.doSubscribe(ZookeeperRegistry.java:176) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:299) ~[dubbo-2.7.10.jar!/:2.7.10]
... 33 more
Caused by: java.lang.InterruptedException
at java.lang.Object.wait(Native Method) ~[?:1.8.0_111]
at java.lang.Object.wait(Object.java:502) ~[?:1.8.0_111]
at org.apache.zookeeper.ClientCnxn.submitRequest(ClientCnxn.java:1409) ~[zookeeper-3.4.11.jar!/:3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0]
at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1651) ~[zookeeper-3.4.11.jar!/:3.4.11-37e277162d567b55a07d1755f0b31c32e93c01a0]
at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:242) ~[curator-framework-4.0.1.jar!/:4.0.1]
at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:231) ~[curator-framework-4.0.1.jar!/:4.0.1]
at org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:64) ~[curator-client-4.0.1.jar!/:?]
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:100) ~[curator-client-4.0.1.jar!/:?]
at org.apache.curator.framework.imps.GetChildrenBuilderImpl.pathInForeground(GetChildrenBuilderImpl.java:228) ~[curator-framework-4.0.1.jar!/:4.0.1]
at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:219) ~[curator-framework-4.0.1.jar!/:4.0.1]
at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:41) ~[curator-framework-4.0.1.jar!/:4.0.1]
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.addTargetChildListener(CuratorZookeeperClient.java:211) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.remoting.zookeeper.curator.CuratorZookeeperClient.addTargetChildListener(CuratorZookeeperClient.java:53) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.remoting.zookeeper.support.AbstractZookeeperClient.addChildListener(AbstractZookeeperClient.java:112) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.registry.zookeeper.ZookeeperRegistry.doSubscribe(ZookeeperRegistry.java:176) ~[dubbo-2.7.10.jar!/:2.7.10]
at org.apache.dubbo.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:299) ~[dubbo-2.7.10.jar!/:2.7.10]
... 33 more
@i will solve it@
CountDownLatch是要释放的,否则会有一条线程一直等待在org.apache.dubbo.registry.zookeeper.ZookeeperRegistry.RegistryChildListenerImpl#childChanged,至于提供者实例列表不更新,根据异常日志,我怀疑是网络原因导致,所以我先提交了释放CountDownLatch的逻辑。