Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore deserilization when service/method not found #5733

Merged
merged 14 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public ServiceDescriptor registerService(String path, Class<?> interfaceClass) {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -72,6 +73,7 @@ public static RegistryProtocol getRegistryProtocol() {
@BeforeEach
public void setUp() {
ApplicationModel.setApplication("RegistryProtocolTest");
ApplicationModel.getServiceRepository().registerService(RegistryService.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class RegistryStatusCheckerTest {
@BeforeEach
public void setUp() {
AbstractRegistryFactory.clearRegistryNotDestroy();
ApplicationModel.getServiceRepository().registerService(RegistryService.class);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -123,6 +124,7 @@ private static String exportOrUnexportCallbackService(Channel channel, URL url,
// 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);
Expand Down Expand Up @@ -160,6 +162,7 @@ private static Object referOrDestroyCallbackService(Channel channel, URL url, Cl
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));
Expand All @@ -172,9 +175,9 @@ private static Object referOrDestroyCallbackService(Channel channel, URL url, Cl
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.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand Down Expand Up @@ -129,6 +130,9 @@ public Object decode(Channel channel, InputStream input) throws IOException {
}
}
if (pts == DubboCodec.EMPTY_CLASS_ARRAY) {
if (!RpcUtils.isGenericCall(path, getMethodName()) && !RpcUtils.isEcho(path, getMethodName())) {
chickenlj marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalArgumentException("Service not found:" + path + ", " + getMethodName());
}
pts = ReflectUtils.desc2classArray(desc);
}
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -57,11 +58,14 @@ public void exportService() {
// 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);
}

Expand Down Expand Up @@ -91,6 +95,7 @@ public void initOrResetService() {
}

public void destroyService() {
ApplicationModel.getServiceRepository().destroy();
demoProxy = null;
try {
if (exporter != null) exporter.unexport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -35,6 +36,7 @@

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;
Expand All @@ -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
Expand Down Expand Up @@ -148,6 +156,9 @@ public void testDubboProtocolMultiService() throws Exception {
// 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
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;
Expand All @@ -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")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@
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;

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;
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand All @@ -45,6 +46,9 @@ public void testNormal() {
+ "&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);

Expand Down Expand Up @@ -88,6 +92,9 @@ public void testNormalEnum() {
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);

Expand All @@ -109,6 +116,9 @@ public void testEnumCompat() {
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);
Expand Down