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 017e4a93df3..262ab701876 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 @@ -437,6 +437,9 @@ public void destroy() { } } } + // put here to reduce the chance of accepting new invocation after client closed. + // close invoker and then client. + super.destroy(); for (String key : new ArrayList(referenceClientMap.keySet())) { ExchangeClient client = referenceClientMap.remove(key); @@ -466,6 +469,5 @@ public void destroy() { } } stubServiceMethodsMap.clear(); - super.destroy(); } } 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 235af3986d4..bc230a26dbf 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 @@ -115,7 +115,7 @@ public ResponseFuture request(Object request, int timeout) throws RemotingExcept private void warning(Object request) { if (requestWithWarning) { if (warningcount.get() % 5000 == 0) { - logger.warn(new IllegalStateException("safe guard client , should not be called ,must have a bug.")); + logger.warn(url.getAddress() + " " + url.getServiceKey() + " safe guard client get called after real client closed, recreating connection..."); } warningcount.incrementAndGet(); } 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 4a6e96593d0..caed5008ef5 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 @@ -167,11 +167,9 @@ public void startClose() { 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.TRUE) - .addParameter(Constants.RECONNECT_KEY, Boolean.FALSE) .addParameter(Constants.SEND_RECONNECT_KEY, Boolean.TRUE.toString()) - .addParameter("warning", Boolean.TRUE.toString()) - .addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true) - .addParameter("_client_memo", "referencecounthandler.replacewithlazyclient"); + .addParameter(LazyConnectExchangeClient.REQUEST_WITH_WARNING_KEY, true); + String key = url.getAddress(); // in worst case there's only one ghost connection. diff --git a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java index d9b64c2fa3b..452e6a919e1 100644 --- a/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java +++ b/dubbo-rpc/dubbo-rpc-dubbo/src/test/java/com/alibaba/dubbo/rpc/protocol/dubbo/ReferenceCountExchangeClientTest.java @@ -26,7 +26,6 @@ import com.alibaba.dubbo.rpc.Exporter; import com.alibaba.dubbo.rpc.Invoker; import com.alibaba.dubbo.rpc.ProxyFactory; - import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; @@ -46,7 +45,7 @@ public class ReferenceCountExchangeClientTest { IHelloService helloService; ExchangeClient demoClient; ExchangeClient helloClient; - String errorMsg = "safe guard client , should not be called ,must have a bug"; + String errorMsg = "safe guard client"; @BeforeClass public static void setUpBeforeClass() throws Exception {