apache / apache/servicecomb-java-chassis
调用三方时负载均衡失败导致业务代码获取contextMgr为空
- Langage dominant
- Java
- Étoiles
- 1.9k
- Forks
- 814
- Merge moyen
- 8 j 23 h
- PR mergées (30 j)
- 1
Description
版本: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)
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par suivre le chemin d’échec de LoadBalancer.chooseServer à travers InvokerUtils.reactiveInvoke et le callback AsyncResponse montré dans l’issue. Examinez comment ContextUtils gère le contexte d’invocation autour de invocation.next et comparez-le à l’appelant de CompletableFuture.get. C’est terminé lorsque l’appel échoué à un tiers ne laisse plus le code métier avec un contextMgr null ; ajoutez ou exécutez une couverture de régression pour ce chemin d’échec.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 35/100