apache / apache/incubator-seata
seata1.5.2|1.6 saga模式存在 java.lang.NullPointerException: null at java.base/java.util.Date.getMillisOf(Date.java:956) bug
- Dominant language
- Java
- Stars
- 26k
- Forks
- 8.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 4
Description
问题描述:saga模式时,客户端调用两个服务,这两个服务都有补偿服务,例如:
A服务 -- 补偿服务为 AU
B服务 -- 补偿服务为 BU
seata服务为远程服务模式。
当客户端运行时,根据流程定义先执行A服务,再执行B服务,此时B服务出现异常,根据流程定义如果抛出异常则触发补偿机制,即开始执行BU服务,然后再执行AU服务。这个是正常流程。
如果在执行BU服务还有没有结束时,强制停止运行(模拟挂机),此时BU这个补偿服务在seata_state_inst表里的记录的gmt_end为null,下次再重新运行客户端时,seata服务会远程触发二阶段回滚,二阶段回滚成功后,我再调用如下代码:
```
String instancdID = stateMachineEngine.getStateMachineConfig().getStateLogStore().
getStateMachineInstanceByBusinessKey(businessKey, null).getId();
```
会导致如下异常:

分析原因知道是由于代码里没有判断gmt_end=null的情况,下方代码出错位置如下:

Contributor guide
Research direction
Start at getStateMachineInstanceByBusinessKey and trace the saga state-log lookup for the seata_state_inst row left with gmt_end=null after BU is interrupted. Reproduce the resumed remote rollback flow and verify that querying the instance after the rollback no longer raises the Date.getMillisOf null-related exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases, distributed-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100