apache / apache/dubbo

dubbo3.1.5添加自定义Filter调用异常

Open
#11,466 7 comments 1 reaction 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

### Environment

* Dubbo version: 3.1.5
* Java version: 1.8

### Steps to reproduce this issue

1.成功调用到提供端,但是返回异常,返回报:
[DUBBO] Decode rpc invocation failed: null, dubbo version: 3.1.5, current host: 192.168.0.190, error code: 4-20. This may be caused by , go to https://dubbo.apache.org/faq/4/20 to find instructions.

java.lang.NullPointerException: null
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936)
at org.apache.dubbo.rpc.support.GroupServiceKeyCache.getServiceKey(GroupServiceKeyCache.java:37)
at org.apache.dubbo.rpc.support.ProtocolUtils.serviceKey(ProtocolUtils.java:51)
at org.apache.dubbo.rpc.protocol.AbstractProtocol.serviceKey(AbstractProtocol.java:83)
at org.apache.dubbo.rpc.protocol.dubbo.DubboProtocol.getInvoker(DubboProtocol.java:282)

2.使用的是dubbo 3.1.5
3.通过日志发现消费端会3次进入invoke方法,这个过滤器主要用来设置额外请求参数

过滤器代码如下:
`@Activate(group = {Constants.CONSUMER, Constants.PROVIDER}, order = -1)
public class DubboTenantFilter implements Filter {
protected final Logger log = LoggerFactory.getLogger(this.getClass());

@Override
public Result invoke(Invoker invoker, Invocation invocation) throws RpcException {
//判断是消费者 还是 服务提供者
System.out.println("invoke:"+RpcContext.getContext().isConsumerSide());
if (RpcContext.getContext().isConsumerSide()) {
//消费者 将tenant_id set至上下文中
RpcContext.getContext().setAttachment(DefConstants.TENANT_HEADER_KEY, TenantContextHolder.getTenantId());
} else {
String tenantId = RpcContext.getContext().getAttachment(DefConstants.TENANT_HEADER_KEY);
if(tenantId!=null){
TenantContextHolder.setTenantId(tenantId);
}
}
try {
return invoker.invoke(invocation);
}finally {
if (RpcContext.getContext().isProviderSide()) {
TenantContextHolder.clear();
}
}
}
}`

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with Dubbo 3.1.5 and the shown DubboTenantFilter, then start from the stack trace in GroupServiceKeyCache.java, ProtocolUtils.java, AbstractProtocol.java, and DubboProtocol.java. Trace why the consumer enters invoke three times and determine what causes the null service key; done means the custom filter no longer triggers the decode exception and the RPC response succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.