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

本地存根和本地伪装无法使用 #65

Closed
liuluo129 opened this issue Jul 9, 2014 · 9 comments
Closed

本地存根和本地伪装无法使用 #65

liuluo129 opened this issue Jul 9, 2014 · 9 comments

Comments

@liuluo129
Copy link

liuluo129 commented Jul 9, 2014

文档上写的本地存根和本地伪装在调用失败的时候会进行一些处理,但是我在测试环境使用的时候把全部服务端关掉之后,就无法使用了,再次调用会抛出异常,信息如下:

com.alibaba.dubbo.rpc.RpcException: Forbid consumer 10.0.0.182 access service com.common.service.LogService from registry zookeeper1:2181 use dubbo version 2.4.10, Please check registry access list (whitelist/blacklist).
    at com.alibaba.dubbo.registry.integration.RegistryDirectory.doList(RegistryDirectory.java:586)
    at com.alibaba.dubbo.rpc.cluster.directory.AbstractDirectory.list(AbstractDirectory.java:73)
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.list(AbstractClusterInvoker.java:259)
    at com.alibaba.dubbo.rpc.cluster.support.AbstractClusterInvoker.invoke(AbstractClusterInvoker.java:218)
    at com.alibaba.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker.invoke(MockClusterInvoker.java:72)
    at com.alibaba.dubbo.rpc.proxy.InvokerInvocationHandler.invoke(InvokerInvocationHandler.java:52)
    at com.alibaba.dubbo.common.bytecode.proxy0.addScheduleLog(proxy0.java)

看源码发现RegistryDirectory类中forbidden属性已经变成true了,原因在于没有服务端的时候,会接收到通知,RegistryDirectory类会调用refreshInvoker方法,如下:

private void refreshInvoker(List<URL> invokerUrls){
        if (invokerUrls != null && invokerUrls.size() == 1 && invokerUrls.get(0) != null
                && Constants.EMPTY_PROTOCOL.equals(invokerUrls.get(0).getProtocol())) {
            this.forbidden = true; // 禁止访问
            this.methodInvokerMap = null; // 置空列表
            destroyAllInvokers(); // 关闭所有Invoker

这个时候在去调用stub和mock都会抛出异常。所以我怀疑这个特性根本无法使用,但是文档上写的可以在生产中使用,有使用过这特特性的同学吗

@liuyangc3
Copy link

同样遇到了这个问题,等待高人解答

@gunsnakee
Copy link

本地存根可以用,mock本地伪装用不了。

@leoshus
Copy link

leoshus commented Apr 19, 2016

遇到同样的问题v2.5.3 有解决的吗

@bbiao
Copy link

bbiao commented Mar 7, 2017

2.5.3还是有这个问题

@wuzhefang
Copy link

是不是重启一下服务端,刷新一下服务列表就好了?

@JKAK47
Copy link

JKAK47 commented Sep 1, 2017

dubbo的本地伪装有谁成功实现过。按照dubbo官方文档设置。然后关于服务提供方服务。服务调用方调用接口也是会失败的。

@JKAK47
Copy link

JKAK47 commented Sep 1, 2017

2.5.3 还是有这个不能本地伪装的问题存在

@kitikousei
Copy link

kitikousei commented Sep 26, 2017

在AbstractRegistry中有一段这样的代码

for (Map.Entry<String, List> entry : result.entrySet()) {
String category = entry.getKey();
List categoryList = entry.getValue();
categoryNotified.put(category, categoryList);
saveProperties(url);
listener.notify(categoryList);
}

这里的result内容如下

[providers=[empty://192.168.1.137/com.xxx.xxService?application=myconsume&category=providers&default.check=false&default.mock=true&dubbo=2.5.5&interface=com.xxx.xxService&methods=register&pid=27046side=consumer], configurators=[empty://192.168.1.137/com.xxx.xxService?application=myconsume&category=configurators&default.check=false&default.mock=true&dubbo=2.5.5&interface=com.xxx.xxService&methods=register&pid=27046&side=consumer], routers=[empty://192.168.1.137/com.xxx.xxService?application=myconsume&category=routers&default.check=false&default.mock=true&dubbo=2.5.5&interface=com.xxx.xxService&methods=register&pid=27046&side=consumer]]

在jdk1.7中第一次循环取的是providers。后面的逻辑会去刷新forbidden字段(refreshInvoker方法)。此时是forbidden设置为true,第二次循环会设置为false,第三次会设置成false。此时可以本地伪装。

但是在jdk1.8中第一次循环去的是configurators。后面的逻辑会去刷新forbidden字段(refreshInvoker方法)。此时是forbidden设置为false,第二次循环会设置为true,第三次会设置成true。此时就本地伪装就没法调用

@diecui1202
Copy link

Local stub works only when providers >= 1. Local mock's bug has fixed, please check https://github.com/apache/incubator-dubbo/blob/fd7bab3cdf2650168e9eca625fd5311ffc7b1f5a/dubbo-cluster/src/main/java/com/alibaba/dubbo/rpc/cluster/support/wrapper/MockClusterInvoker.java#L142

Feel free to reopen it or open a new issue if you have any other questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants