添加自定义过滤器后调用异常
- Dominant language
- CSS
- Stars
- 491
- Forks
- 809
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 6
Description
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 = -10000)
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
No contributing guide indexed for this repository
Research direction
Start by reading the reported stack-trace entry points: DubboProtocol.getInvoker, GroupServiceKeyCache.getServiceKey, ProtocolUtils.serviceKey, and the custom filter's invoke method. Reproduce the behavior with Dubbo 3.1.5 and inspect why a null value reaches ConcurrentHashMap.get during the filtered call. Done means the cause is confirmed and the issue has a validated fix or clear documented resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100