You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ky...@apache.org on 2021/07/09 03:00:24 UTC
[dubbo] branch master updated: disable telnet by default and fix ut,
reset resources (#8239)
This is an automated email from the ASF dual-hosted git repository.
kylixs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new 11e15f2 disable telnet by default and fix ut, reset resources (#8239)
11e15f2 is described below
commit 11e15f2a440dc49070ec6e5d6fee2675bc0b2997
Author: ken.lj <ke...@gmail.com>
AuthorDate: Fri Jul 9 11:00:05 2021 +0800
disable telnet by default and fix ut, reset resources (#8239)
---
.../cluster/support/MergeableClusterInvokerTest.java | 3 ++-
.../org/apache/dubbo/common/config/Environment.java | 5 +++++
.../dubbo/common/extension/ExtensionLoader.java | 2 ++
.../org/apache/dubbo/config/DubboShutdownHook.java | 19 +++++++++++++------
.../apache/dubbo/config/bootstrap/DubboBootstrap.java | 18 ++++++++++--------
.../dubbo/config/utils/ReferenceConfigCacheTest.java | 2 ++
.../remoting/telnet/support/TelnetHandlerAdapter.java | 4 ++--
7 files changed, 36 insertions(+), 17 deletions(-)
diff --git a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java
index 975eee6..c22c540 100644
--- a/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java
+++ b/dubbo-cluster/src/test/java/org/apache/dubbo/rpc/cluster/support/MergeableClusterInvokerTest.java
@@ -22,6 +22,7 @@ import org.apache.dubbo.rpc.AsyncRpcResult;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
+import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.cluster.Directory;
import org.junit.jupiter.api.Assertions;
@@ -92,7 +93,7 @@ public class MergeableClusterInvokerTest {
directory = mock(Directory.class);
firstInvoker = mock(Invoker.class);
secondInvoker = mock(Invoker.class);
- invocation = mock(Invocation.class);
+ invocation = mock(RpcInvocation.class);
}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java
index cfc1b01..18c6eef 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/config/Environment.java
@@ -197,6 +197,7 @@ public class Environment extends LifecycleAdapter implements FrameworkExt {
public void destroy() throws IllegalStateException {
clearExternalConfigs();
clearAppExternalConfigs();
+ clearDynamicConfiguration();
}
public PropertiesConfiguration getPropertiesConfiguration() {
@@ -230,4 +231,8 @@ public class Environment extends LifecycleAdapter implements FrameworkExt {
this.appExternalConfiguration.clear();
this.appExternalConfigurationMap.clear();
}
+
+ public void clearDynamicConfiguration() {
+ this.dynamicConfiguration = null;
+ }
}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
index d85a34c..359f2e5 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/extension/ExtensionLoader.java
@@ -206,6 +206,8 @@ public class ExtensionLoader<T> {
}
}
});
+ EXTENSION_INSTANCES.clear();
+ EXTENSION_LOADERS.clear();
}
private static ClassLoader findClassLoader() {
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
index df2a295..9efdc5f 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
@@ -33,7 +33,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
/**
* The shutdown hook thread to do the clean up stuff.
* This is a singleton in order to ensure there is only one shutdown hook registered.
- * Because {@link ApplicationShutdownHooks} use {@link java.util.IdentityHashMap}
* to store the shutdown hooks.
*/
public class DubboShutdownHook extends Thread {
@@ -52,7 +51,7 @@ public class DubboShutdownHook extends Thread {
/**
* Has it already been destroyed or not?
*/
- private static final AtomicBoolean destroyed = new AtomicBoolean(false);
+ private final AtomicBoolean destroyed = new AtomicBoolean(false);
private final EventDispatcher eventDispatcher = EventDispatcher.getDefaultExtension();
@@ -90,6 +89,7 @@ public class DubboShutdownHook extends Thread {
*/
public void register() {
if (registered.compareAndSet(false, true)) {
+ destroyed.set(false);
DubboShutdownHook dubboShutdownHook = getDubboShutdownHook();
Runtime.getRuntime().addShutdownHook(dubboShutdownHook);
dispatch(new DubboShutdownHookRegisteredEvent(dubboShutdownHook));
@@ -113,6 +113,10 @@ public class DubboShutdownHook extends Thread {
public void doDestroy() {
// dispatch the DubboDestroyedEvent @since 2.7.5
dispatch(new DubboServiceDestroyedEvent(this));
+ if (destroyed.compareAndSet(false, true)) {
+ AbstractRegistryFactory.destroyAll();
+ destroyProtocols();
+ }
}
private void dispatch(Event event) {
@@ -124,10 +128,7 @@ public class DubboShutdownHook extends Thread {
}
public static void destroyAll() {
- if (destroyed.compareAndSet(false, true)) {
- AbstractRegistryFactory.destroyAll();
- destroyProtocols();
- }
+ getDubboShutdownHook().doDestroy();
}
/**
@@ -146,4 +147,10 @@ public class DubboShutdownHook extends Thread {
}
}
}
+
+ public static void reset() {
+ getDubboShutdownHook().destroyed.set(false);
+ getDubboShutdownHook().unregister();
+ }
+
}
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
index 8bf3c9d..b5928c1 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/bootstrap/DubboBootstrap.java
@@ -876,6 +876,7 @@ public class DubboBootstrap {
*/
public DubboBootstrap start() {
if (started.compareAndSet(false, true)) {
+ destroyed.set(false);
ready.set(false);
initialize();
if (logger.isInfoEnabled()) {
@@ -1258,16 +1259,15 @@ public class DubboBootstrap {
public void destroy() {
if (destroyLock.tryLock()) {
try {
- if (started.compareAndSet(true, false)
- && destroyed.compareAndSet(false, true)) {
-
- unregisterServiceInstance();
- unexportMetadataService();
- unexportServices();
- unreferServices();
+ if (destroyed.compareAndSet(false, true)) {
+ if (started.compareAndSet(true, false)) {
+ unregisterServiceInstance();
+ unexportMetadataService();
+ unexportServices();
+ unreferServices();
+ }
destroyRegistries();
-
destroyServiceDiscoveries();
destroyExecutorRepository();
clear();
@@ -1279,6 +1279,7 @@ public class DubboBootstrap {
DubboShutdownHook.destroyAll();
} finally {
+ initialized.set(false);
destroyLock.unlock();
}
}
@@ -1428,6 +1429,7 @@ public class DubboBootstrap {
*/
@Deprecated
public static void reset(boolean destroy) {
+ DubboShutdownHook.reset();
if (destroy) {
if (instance != null) {
instance.destroy();
diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java
index 055daff..7d79f22 100644
--- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java
+++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/utils/ReferenceConfigCacheTest.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.config.utils;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.utils.service.FooService;
import org.junit.jupiter.api.BeforeEach;
@@ -33,6 +34,7 @@ public class ReferenceConfigCacheTest {
public void setUp() throws Exception {
MockReferenceConfig.setCounter(0);
ReferenceConfigCache.CACHE_HOLDER.clear();
+ DubboBootstrap.reset();
}
@Test
diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
index 95eb575..8fb0ab0 100644
--- a/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
+++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/telnet/support/TelnetHandlerAdapter.java
@@ -67,7 +67,7 @@ public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements Telne
} else {
buf.append("Command: ");
buf.append(command);
- buf.append(" disabled");
+ buf.append(" disabled for security reasons, please enable support by listing the commands through 'telnet'");
}
} else {
buf.append("Unsupported command: ");
@@ -86,7 +86,7 @@ public class TelnetHandlerAdapter extends ChannelHandlerAdapter implements Telne
private boolean commandEnabled(URL url, String command) {
String supportCommands = url.getParameter(TELNET);
if (StringUtils.isEmpty(supportCommands)) {
- return true;
+ return false;
}
String[] commands = COMMA_SPLIT_PATTERN.split(supportCommands);
for (String c : commands) {