apache / apache/dubbo

RpcContext获取参数问题

Open
#11,876 25 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

system:centos7.9
jdk:11
dubbo:3.1.4
序列化:kryo1.0.1
问题:在消费者透传信息给提供者时,在提供者的方法第一行是可以获取到透传信息,但是在方法执行期间和执行末尾获取透传信息则为空,但是相同的案例 我把dubbo版本切回到3.1.0版本则一切正常,不太理解是因为什么原因造成的,还是官方已经得知该问题并修复了。

提供者代码如下:
```
@Override
public PageVo querySysUserByPage(PageDto pageDto, QuerySysUserByPageDto dto) {
log.info("查询用户分页开始:{}",AdminRpcContext.getUser());
// 统计
Integer totalRowSize = userMapper.querySysUserByCount(dto);
if (totalRowSize == 0) return null;
// 计算分页
PageOperationResultBo page = PageOperationTools.operationPage(pageDto, totalRowSize);
// 查询分页结果
List voList = userMapper.querySysUserByPage(page, dto);
// 填充角色以及岗位
voList.forEach(vo -> {
vo.setRolesVo(userRoleMapper.querySysRolePersonalInfoList(vo.getId()));
vo.setPostsVo(userPostMapper.querySysPostPersonalInfoList(vo.getId()));
});
log.info("查询用户分页完成:{}",AdminRpcContext.getUser());
return PageVo.build(page, voList);
}
```

**3.1.4版本获取rpc透传信息大致打印如下:**
```
2023-03-21 15:04:03.038 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.user.service.service.sys.SysUserServiceImp - 查询用户分页开始:AdminUserBo(id=1)
2023-03-21 15:04:03.038 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:04:03.055 [DubboServerHandler-172.18.0.1:20100-thread-6] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:04:04.039 [DubboServerHandler-172.18.0.1:20100-thread-6] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:04:04.042 [DubboServerHandler-172.18.0.1:20100-thread-6] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:04:04.042 [DubboServerHandler-172.18.0.1:20100-thread-6] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:04:04.049 [DubboServerHandler-172.18.0.1:20100-thread-6] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:04:04.081 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.s.core.mybatis.hanlder.MybatisQueryHandler - 旧sql:[1],数据权限:select count(*)
2023-03-21 15:04:04.200 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:null
2023-03-21 15:04:04.211 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:null
2023-03-21 15:04:04.215 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional[org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.LockSegment@4233467d], window=Optional.empty)
2023-03-21 15:04:04.215 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:04:04.220 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:null
2023-03-21 15:04:04.221 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:04:04.221 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:04:04.225 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:null
2023-03-21 15:04:04.226 [DubboServerHandler-172.18.0.1:20100-thread-7] INFO ShardingSphere-SQL - Logic SQL: select

2023-03-21 15:04:04.281 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:04:04.288 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:null
2023-03-21 15:04:04.318 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:04:04.318 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:04:04.324 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:null
2023-03-21 15:04:04.369 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.user.service.service.sys.SysUserServiceImp - 查询用户分页完成:null
```
**3.1.0版本获取rpc透传信息大致打印如下:**
```
2023-03-21 15:08:07.774 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO c.l.p.user.service.service.sys.SysUserServiceImp - 查询用户分页开始:AdminUserBo(id=1)
2023-03-21 15:08:07.790 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:07.842 [DubboServerHandler-172.18.0.1:20100-thread-4] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:08.749 [DubboServerHandler-172.18.0.1:20100-thread-4] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:08.749 [DubboServerHandler-172.18.0.1:20100-thread-4] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:08.900 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - Logic SQL: SELECT count(*) FROM sys_user WHERE id = ? AND create_user_id IN (1)
2023-03-21 15:08:08.900 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:08.900 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:08.907 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:08.922 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:08.926 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional[org.apache.shardingsphere.sql.parser.sql.common.segment.dml.predicate.LockSegment@5d9c13de], window=Optional.empty)
2023-03-21 15:08:08.926 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:08.930 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:08.931 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:08.931 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:08.935 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:08.935 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:08.935 [DubboServerHandler-172.18.0.1:20100-thread-5] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:09.046 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - Logic SQL: SELECT users.id, users.dept_id, dept.name AS deptName, users.username, users.nickname, users.status, users.update_user_id, users.update_time, users.create_user_id, users.create_time FROM sys_user AS users LEFT JOIN sys_dept AS dept ON users.dept_id = dept.id WHERE users.id = ? AND users.create_user_id IN (1) ORDER BY users.id DESC LIMIT ?, ?
2023-03-21 15:08:09.046 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional[org.apache.shardingsphere.sql.parser.sql.common.segment.dml.pagination.limit.LimitSegment@1919f13b], lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:09.046 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:09.052 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)
2023-03-21 15:08:09.090 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:09.091 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:09.095 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO c.l.p.service.core.mybatis.MybatisInterceptor - 拦截器获取:AdminUserBo(id=1)erPost.post_id = post.id
2023-03-21 15:08:09.098 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - SQLStatement: MySQLSelectStatement(table=Optional.empty, limit=Optional.empty, lock=Optional.empty, window=Optional.empty)
2023-03-21 15:08:09.098 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO ShardingSphere-SQL - Actual SQL(simple): [master_0] ::: 1
2023-03-21 15:08:09.102 [DubboServerHandler-172.18.0.1:20100-thread-3] INFO c.l.p.user.service.service.sys.SysUserServiceImp - 查询用户分页完成:AdminUserBo(id=1)
```
可以看到在3.1.0版本上从方法执行到末尾都可以正常拿到RpcContext参数

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the provider call with Dubbo 3.1.4 and compare RpcContext behavior against 3.1.0, using the shown service method and MybatisInterceptor logs. Trace where the propagated parameter becomes null during method execution, then verify it remains available through the final log and add regression coverage for the reported version difference.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.