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/02/23 17:24:38 UTC
[dubbo] branch 2.6.x updated: Solve the problem of not sharing the
shared connection under lazy mode (#7245)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 2.6.x
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/2.6.x by this push:
new 34d1a37 Solve the problem of not sharing the shared connection under lazy mode (#7245)
34d1a37 is described below
commit 34d1a3724ddb65f02682ca830789a95a033eb428
Author: xiaoheng1 <20...@qq.com>
AuthorDate: Wed Feb 24 01:24:09 2021 +0800
Solve the problem of not sharing the shared connection under lazy mode (#7245)
* fix #7186 Solve the problem of not sharing the shared connection under lazy mode.
* fix #7186 Solve the problem that dubboProtocol of junit unit test case is not isolated.
* fix #7186 Solve when closing the connection, set LAZY_CONNECT_INITIAL_STATE_KEY to true.
---
.../rpc/protocol/dubbo/LazyConnectExchangeClient.java | 17 +++++++++--------
.../protocol/dubbo/ReferenceCountExchangeClient.java | 2 +-
.../rpc/protocol/dubbo/DubboInvokerAvilableTest.java | 3 ++-
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/LazyConnectExchangeClient.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/LazyConnectExchangeClient.java
index bc14eba..235af39 100644
--- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/LazyConnectExchangeClient.java
+++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/LazyConnectExchangeClient.java
@@ -62,15 +62,17 @@ final class LazyConnectExchangeClient implements ExchangeClient {
private void initClient() throws RemotingException {
- if (client != null)
+ if (client != null) {
return;
+ }
if (logger.isInfoEnabled()) {
logger.info("Lazy connect to " + url);
}
connectLock.lock();
try {
- if (client != null)
+ if (client != null) {
return;
+ }
this.client = Exchangers.connect(url, requestHandler);
} finally {
connectLock.unlock();
@@ -162,22 +164,21 @@ final class LazyConnectExchangeClient implements ExchangeClient {
@Override
public boolean isClosed() {
- if (client != null)
- return client.isClosed();
- else
- return true;
+ return (null != client) ? client.isClosed() : false;
}
@Override
public void close() {
- if (client != null)
+ if (client != null) {
client.close();
+ }
}
@Override
public void close(int timeout) {
- if (client != null)
+ if (client != null) {
client.close(timeout);
+ }
}
@Override
diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java
index e60ce51..4a6e965 100644
--- a/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java
+++ b/dubbo-rpc/dubbo-rpc-dubbo/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClient.java
@@ -166,7 +166,7 @@ final class ReferenceCountExchangeClient implements ExchangeClient {
// ghost client
private LazyConnectExchangeClient replaceWithLazyClient() {
// this is a defensive operation to avoid client is closed by accident, the initial state of the client is false
- URL lazyUrl = url.addParameter(Constants.LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.FALSE)
+ URL lazyUrl = url.addParameter(Constants.LAZY_CONNECT_INITIAL_STATE_KEY, Boolean.TRUE)
.addParameter(Constants.RECONNECT_KEY, Boolean.FALSE)
.addParameter(Constants.SEND_RECONNECT_KEY, Boolean.TRUE.toString())
.addParameter("warning", Boolean.TRUE.toString())
diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboInvokerAvilableTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboInvokerAvilableTest.java
index 8d33733..42bbd76 100644
--- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboInvokerAvilableTest.java
+++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/DubboInvokerAvilableTest.java
@@ -43,7 +43,7 @@ public class DubboInvokerAvilableTest {
private final static Logger logger = LoggerFactory.getLogger(DubboInvokerAvilableTest.class);
- private static DubboProtocol protocol = DubboProtocol.getDubboProtocol();
+ private static DubboProtocol protocol;
private static ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
@BeforeClass
@@ -52,6 +52,7 @@ public class DubboInvokerAvilableTest {
@Before
public void setUp() throws Exception {
+ protocol = new DubboProtocol();
}
@Test