Ignore deserilization when service/method not found (#5733)

This commit is contained in:
ken.lj 2020-05-01 15:45:39 +08:00 committed by GitHub
parent c28171be8f
commit 04fc3ce4cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 66 additions and 1 deletions

View File

@ -14,6 +14,8 @@ Apache Dubbo is a high-performance, Java based open source RPC framework. Please
We are now collecting dubbo user info in order to help us to improve Dubbo better, pls. kindly help us by providing yours on [issue#1012: Wanted: who's using dubbo](https://github.com/apache/dubbo/issues/1012), thanks :)
[使用文档](http://dubbo.apache.org/zh-cn/docs/user/new-features-in-a-glance.html)/[Documentation](http://dubbo.apache.org/en-us/docs/user/quick-start.html)
## Architecture
![Architecture](http://dubbo.apache.org/img/architecture.png)

View File

@ -85,6 +85,14 @@ public class ServiceRepository extends LifecycleAdapter implements FrameworkExt
return serviceDescriptor;
}
public void unregisterService(Class<?> interfaceClazz) {
unregisterService(interfaceClazz.getName());
}
public void unregisterService(String path) {
services.remove(path);
}
public void registerConsumer(String serviceKey,
ServiceDescriptor serviceDescriptor,
ReferenceConfigBase<?> rc,

View File

@ -21,6 +21,7 @@ import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.registry.NotifyListener;
import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.RegistryService;
import org.apache.dubbo.registry.integration.RegistryProtocol;
import org.apache.dubbo.registry.support.AbstractRegistry;
import org.apache.dubbo.remoting.exchange.ExchangeClient;
@ -72,6 +73,7 @@ public class RegistryProtocolTest {
@BeforeEach
public void setUp() {
ApplicationModel.setApplication("RegistryProtocolTest");
ApplicationModel.getServiceRepository().registerService(RegistryService.class);
}
@Test

View File

@ -20,6 +20,7 @@ import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.status.Status;
import org.apache.dubbo.registry.RegistryFactory;
import org.apache.dubbo.registry.RegistryService;
import org.apache.dubbo.registry.status.RegistryStatusChecker;
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
@ -47,6 +48,7 @@ public class RegistryStatusCheckerTest {
@BeforeEach
public void setUp() {
AbstractRegistryFactory.clearRegistryNotDestroy();
ApplicationModel.getServiceRepository().registerService(RegistryService.class);
}
@Test

View File

@ -30,6 +30,7 @@ import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.AsyncToSyncInvoker;
import java.io.IOException;
@ -123,6 +124,7 @@ class CallbackServiceCodec {
// one channel can have multiple callback instances, no need to re-export for different instance.
if (!channel.hasAttribute(cacheKey)) {
if (!isInstancesOverLimit(channel, url, clazz.getName(), instid, false)) {
ApplicationModel.getServiceRepository().registerService(clazz);
Invoker<?> invoker = PROXY_FACTORY.getInvoker(inst, clazz, exportUrl);
// should destroy resource?
Exporter<?> exporter = PROTOCOL.export(invoker);
@ -160,6 +162,7 @@ class CallbackServiceCodec {
URL referurl = URL.valueOf("callback://" + url.getAddress() + "/" + clazz.getName() + "?" + INTERFACE_KEY + "=" + clazz.getName());
referurl = referurl.addParametersIfAbsent(url.getParameters()).removeParameter(METHODS_KEY);
if (!isInstancesOverLimit(channel, referurl, clazz.getName(), instid, true)) {
ApplicationModel.getServiceRepository().registerService(clazz);
@SuppressWarnings("rawtypes")
Invoker<?> invoker = new ChannelWrappedInvoker(clazz, channel, referurl, String.valueOf(instid));
proxy = PROXY_FACTORY.getProxy(new AsyncToSyncInvoker<>(invoker));
@ -172,9 +175,9 @@ class CallbackServiceCodec {
Set<Invoker<?>> callbackInvokers = (Set<Invoker<?>>) channel.getAttribute(CHANNEL_CALLBACK_KEY);
if (callbackInvokers == null) {
callbackInvokers = new ConcurrentHashSet<>(1);
callbackInvokers.add(invoker);
channel.setAttribute(CHANNEL_CALLBACK_KEY, callbackInvokers);
}
callbackInvokers.add(invoker);
logger.info("method " + inv.getMethodName() + " include a callback service :" + invoker.getUrl() + ", a proxy :" + invoker + " has been created.");
}
}

View File

@ -34,6 +34,7 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.model.MethodDescriptor;
import org.apache.dubbo.rpc.model.ServiceDescriptor;
import org.apache.dubbo.rpc.model.ServiceRepository;
import org.apache.dubbo.rpc.support.RpcUtils;
import java.io.IOException;
import java.io.InputStream;
@ -129,6 +130,9 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
}
}
if (pts == DubboCodec.EMPTY_CLASS_ARRAY) {
if (!RpcUtils.isGenericCall(path, getMethodName()) && !RpcUtils.isEcho(path, getMethodName())) {
throw new IllegalArgumentException("Service not found:" + path + ", " + getMethodName());
}
pts = ReflectUtils.desc2classArray(desc);
}
// }

View File

@ -21,6 +21,7 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils;
import org.junit.jupiter.api.AfterEach;
@ -57,11 +58,14 @@ public class ArgumentCallbackTest {
// export one service first, to test connection sharing
serviceURL = serviceURL.addParameter("connections", 1);
URL hellourl = serviceURL.setPath(IHelloService.class.getName());
ApplicationModel.getServiceRepository().registerService(IDemoService.class);
ApplicationModel.getServiceRepository().registerService(IHelloService.class);
hello_exporter = ProtocolUtils.export(new HelloServiceImpl(), IHelloService.class, hellourl);
exporter = ProtocolUtils.export(new DemoServiceImpl(), IDemoService.class, serviceURL);
}
void referService() {
ApplicationModel.getServiceRepository().registerService(IDemoService.class);
demoProxy = (IDemoService) ProtocolUtils.refer(IDemoService.class, consumerUrl);
}
@ -91,6 +95,7 @@ public class ArgumentCallbackTest {
}
public void destroyService() {
ApplicationModel.getServiceRepository().destroy();
demoProxy = null;
try {
if (exporter != null) exporter.unexport();

View File

@ -24,6 +24,7 @@ import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService;
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl;
import org.apache.dubbo.rpc.protocol.dubbo.support.NonSerialized;
@ -35,6 +36,7 @@ import org.apache.dubbo.rpc.service.EchoService;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
@ -54,6 +56,12 @@ public class DubboProtocolTest {
@AfterAll
public static void after() {
ProtocolUtils.closeAll();
ApplicationModel.getServiceRepository().unregisterService(DemoService.class);
}
@BeforeAll
public static void setup() {
ApplicationModel.getServiceRepository().registerService(DemoService.class);
}
@Test
@ -148,6 +156,9 @@ public class DubboProtocolTest {
// 3000L)));
RemoteService remote = new RemoteServiceImpl();
ApplicationModel.getServiceRepository().registerService(RemoteService.class);
int port = NetUtils.getAvailablePort();
protocol.export(proxy.getInvoker(remote, RemoteService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + RemoteService.class.getName())));
remote = proxy.getProxy(protocol.refer(RemoteService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/" + RemoteService.class.getName()).addParameter("timeout",

View File

@ -22,9 +22,11 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService;
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoServiceImpl;
import org.apache.dubbo.rpc.protocol.dubbo.support.ProtocolUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -42,10 +44,12 @@ public class MultiThreadTest {
@AfterEach
public void after() {
ProtocolUtils.closeAll();
ApplicationModel.getServiceRepository().destroy();
}
@Test
public void testDubboMultiThreadInvoke() throws Exception {
ApplicationModel.getServiceRepository().registerService("TestService", DemoService.class);
int port = NetUtils.getAvailablePort();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(new DemoServiceImpl(), DemoService.class, URL.valueOf("dubbo://127.0.0.1:" + port + "/TestService")));

View File

@ -31,6 +31,7 @@ import org.apache.dubbo.remoting.transport.netty4.NettyBackedChannelBuffer;
import org.apache.dubbo.remoting.transport.netty4.NettyCodecAdapter;
import org.apache.dubbo.rpc.AppResponse;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation;
import org.apache.dubbo.rpc.protocol.dubbo.DubboCodec;
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService;
@ -38,7 +39,9 @@ import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.embedded.EmbeddedChannel;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.IOException;
@ -62,6 +65,17 @@ public class DubboTelnetDecodeTest {
private static AtomicInteger telnetTelnet = new AtomicInteger(0);
@BeforeAll
public static void setup() {
ApplicationModel.getServiceRepository().destroy();
ApplicationModel.getServiceRepository().registerService(DemoService.class);
}
@AfterAll
public static void teardown() {
ApplicationModel.getServiceRepository().destroy();
}
/**
* just dubbo request
*

View File

@ -23,6 +23,7 @@ import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.service.GenericService;
import org.junit.jupiter.api.Assertions;
@ -45,6 +46,9 @@ public class EnumBak {
+ "&timeout=" + Integer.MAX_VALUE
);
DemoService demo = new DemoServiceImpl();
ApplicationModel.getServiceRepository().registerService("test", DemoService.class);
Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
protocol.export(invoker);
@ -88,6 +92,9 @@ public class EnumBak {
URL serviceurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE
);
DemoService demo = new DemoServiceImpl();
ApplicationModel.getServiceRepository().registerService("test", DemoService.class);
Invoker<DemoService> invoker = proxy.getInvoker(demo, DemoService.class, serviceurl);
protocol.export(invoker);
@ -109,6 +116,9 @@ public class EnumBak {
int port = NetUtils.getAvailablePort();
URL consumerurl = URL.valueOf("dubbo://127.0.0.1:" + port + "/test?timeout=" + Integer.MAX_VALUE
);
ApplicationModel.getServiceRepository().registerService(DemoService.class);
Invoker<DemoService> reference = protocol.refer(DemoService.class, consumerurl);
DemoService demoProxy = (DemoService) proxy.getProxy(reference);
Type type = demoProxy.enumlength(Type.High);