apache / apache/servicecomb-java-chassis
调用三方时负载均衡失败导致业务代码获取contextMgr为空
- 主要语言
- Java
- 星标
- 1.9k
- 派生
- 814
- 平均合并
- 8 天 23 小时
- 30 天内合并 PR
- 1
描述
版本:1.3.10
代码实现:业务为REST接口,非Reactive模式,业务调用三方接口为Reactive模式,调用三方结束后,通过CompletableFuture的get方法获取三方调用结果后返回。
问题场景:压测的过程中,因三方未扩容,压测一段时间后负载均衡失败,LoadBalancer.chooseServer返回null,导致了InvokerUtils的reactiveInvoke方法传给invocation.next的AsyncResponse被调用:
```
invocation.next(ar -> {
ContextUtils.setInvocationContext(invocation.getParentContext());
try {
invocation.getInvocationStageTrace().finishHandlersResponse();
invocation.onFinish(ar);
asyncResp.handle(ar);
} finally {
ContextUtils.removeInvocationContext();
}
});
```
以上的ContextUtils.removeInvocationContext()语句执行,导致ContextUtils中的contextMgr被清理,如下业务代码执行触发空指针异常:
ContextUtils.getInvocationContext().getLocalContext().put(CommonConstant.RETURN_CODE,0)
贡献指南
这个仓库没有索引到贡献指南
调研方向
首先,沿着 issue 中所示的 AsyncResponse 回调,通过 InvokerUtils.reactiveInvoke 跟踪失败的 LoadBalancer.chooseServer 路径。检查 ContextUtils 如何在 invocation.next 周围管理调用上下文,并将其与 CompletableFuture.get 的调用方进行比较。当失败的第三方调用不再使业务代码处于 contextMgr 为 null 的状态时,即视为完成;为此失败路径添加或运行回归覆盖。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 35/100