[Transaction] Fix end transaction at state of timeout
### Motivation
For concurrency problems, timeout may change the status to timeout before commit/abort changes the status to committing/aborting.
### Modification
Cancel timeout when commit or abort and then check the state.
@@ -165,10 +165,10 @@ public class TransactionImpl implements Transaction , TimerTask {
@Override
public CompletableFuture<Void> commit() {
+ timeout.cancel();
return checkIfOpenOrCommitting().thenCompose((value) -> {
CompletableFuture<Void> commitFuture = new CompletableFuture<>();
this.state = State.COMMITTING;
- timeout.cancel();
allOpComplete().whenComplete((v, e) -> {
if (e != null) {
abort().whenComplete((vx, ex) -> commitFuture.completeExceptionally(e));
@@ -194,10 +194,10 @@ public class TransactionImpl implements Transaction , TimerTask {
@Override
public CompletableFuture<Void> abort() {
+ timeout.cancel();
return checkIfOpenOrAborting().thenCompose(value -> {
CompletableFuture<Void> abortFuture = new CompletableFuture<>();
this.state = State.ABORTING;
- timeout.cancel();
allOpComplete().whenComplete((v, e) -> {
if (e != null) {
log.error(e.getMessage());
