You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by yi...@apache.org on 2018/07/26 12:21:19 UTC

[incubator-dubbo] branch master updated: Fix a bug when client reconnect (#2135)

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

yiji 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 e90d95c  Fix a bug when client reconnect (#2135)
e90d95c is described below

commit e90d95c0d9f1d0fecf411ccf9066d74c88442c6e
Author: 时无两丶 <44...@qq.com>
AuthorDate: Thu Jul 26 20:21:01 2018 +0800

    Fix a bug when client reconnect (#2135)
    
    * Add reconnection lock to control only one thread can can reconnect method.
    This will avoid problem in this case:
    Thread A reconnecting, and success, then send msg.
    Thread B reconnecting but invoke disconnect. Then the Thread A will send msg fail because of Thread B's disconnecting call.
    
    * fix sth
---
 .../org/apache/dubbo/remoting/transport/AbstractClient.java | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
index dd75e5b..a945586 100644
--- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java
@@ -321,8 +321,17 @@ public abstract class AbstractClient extends AbstractEndpoint implements Client
 
     @Override
     public void reconnect() throws RemotingException {
-        disconnect();
-        connect();
+        if (!isConnected()) {
+            connectLock.lock();
+            try {
+                if (!isConnected()) {
+                    disconnect();
+                    connect();
+                }
+            } finally {
+                connectLock.unlock();
+            }
+        }
     }
 
     @Override