You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2018/05/25 02:11:11 UTC

[incubator-dubbo] branch master updated: Merge pull request #1836, there is a potential deadlock in DubboProtocol#getSharedClient.

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 47adfd0  Merge pull request #1836, there is a potential deadlock in DubboProtocol#getSharedClient.
47adfd0 is described below

commit 47adfd047b2df5ab2f5ca9740e85676ce53066f9
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Fri May 25 10:11:07 2018 +0800

    Merge pull request #1836, there is a potential deadlock in DubboProtocol#getSharedClient.
    
    Fixes #677.
---
 .../com/alibaba/dubbo/rpc/protocol/dubbo/DubboProtocol.java    | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboProtocol.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboProtocol.java
index 4e8b971..017e4a9 100644
--- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboProtocol.java
+++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboProtocol.java
@@ -65,6 +65,7 @@ public class DubboProtocol extends AbstractProtocol {
     private final Map<String, ExchangeServer> serverMap = new ConcurrentHashMap<String, ExchangeServer>(); // <host:port,Exchanger>
     private final Map<String, ReferenceCountExchangeClient> referenceClientMap = new ConcurrentHashMap<String, ReferenceCountExchangeClient>(); // <host:port,Exchanger>
     private final ConcurrentMap<String, LazyConnectExchangeClient> ghostClientMap = new ConcurrentHashMap<String, LazyConnectExchangeClient>();
+    private final ConcurrentMap<String, Object> locks = new ConcurrentHashMap<String, Object>();
     private final Set<String> optimizers = new ConcurrentHashSet<String>();
     //consumer side export a stub service for dispatching event
     //servicekey-stubmethods
@@ -373,11 +374,18 @@ public class DubboProtocol extends AbstractProtocol {
                 referenceClientMap.remove(key);
             }
         }
-        synchronized (key.intern()) {
+
+        locks.putIfAbsent(key, new Object());
+        synchronized (locks.get(key)) {
+            if (referenceClientMap.containsKey(key)) {
+                return referenceClientMap.get(key);
+            }
+
             ExchangeClient exchangeClient = initClient(url);
             client = new ReferenceCountExchangeClient(exchangeClient, ghostClientMap);
             referenceClientMap.put(key, client);
             ghostClientMap.remove(key);
+            locks.remove(key);
             return client;
         }
     }

-- 
To stop receiving notification emails like this one, please contact
liujun@apache.org.