Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: fix using @GlobalTransactional in provider ShouldNeverHappenException thrown #5472

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion changes/en-us/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Add changes here for all PR submitted to the develop branch.
- [[#5413](https://github.com/seata/seata/pull/5413)] fix bad service configuration file and compilation failure
- [[#5415](https://github.com/seata/seata/pull/5415)] fix transaction timeout on client side not execute hook and failureHandler
- [[#5447](https://github.com/seata/seata/pull/5447)] fix oracle xa mode cannnot be used By same database

- [[#5472](https://github.com/seata/seata/pull/5472)] fix if using `@GlobalTransactional` in RM, `ShouldNeverHappenException` will be thrown

### optimize:
- [[#5208](https://github.com/seata/seata/pull/5208)] optimize throwable getCause once more
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [[#5413](https://github.com/seata/seata/pull/5413)] 修复 arm64平台下的JDK和Spring兼容问题
- [[#5415](https://github.com/seata/seata/pull/5415)] 修复客户侧事务提交前超时未执行hook和failureHandler的问题
- [[#5447](https://github.com/seata/seata/pull/5447)] fix oracle xa mode cannnot be used By same database
- [[#5472](https://github.com/seata/seata/pull/5472)] 在RM中使用`@GlobalTransactional`时,如果RM执行失败会抛出`ShouldNeverHappenException`


### optimize:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.seata.tm.TransactionManagerHolder;
import io.seata.tm.api.DefaultFailureHandlerImpl;
import io.seata.tm.api.FailureHandler;
import io.seata.tm.api.GlobalTransaction;
import io.seata.tm.api.TransactionalExecutor;
import io.seata.tm.api.TransactionalTemplate;
import io.seata.tm.api.transaction.NoRollbackRule;
Expand All @@ -64,6 +65,7 @@
import static io.seata.common.DefaultValues.DEFAULT_TM_DEGRADE_CHECK_ALLOW_TIMES;
import static io.seata.common.DefaultValues.DEFAULT_TM_DEGRADE_CHECK_PERIOD;
import static io.seata.common.DefaultValues.TM_INTERCEPTOR_ORDER;
import static io.seata.tm.api.GlobalTransactionRole.Participant;

/**
* The type Global transactional interceptor.
Expand Down Expand Up @@ -247,6 +249,12 @@ public TransactionInfo getTransactionInfo() {
}
});
} catch (TransactionalExecutor.ExecutionException e) {
GlobalTransaction globalTransaction = e.getTransaction();

// If Participant, just throw the exception to original.
if (globalTransaction.getGlobalTransactionRole() == Participant) {
throw e.getOriginalException();
}
TransactionalExecutor.Code code = e.getCode();
Throwable cause = e.getCause();
boolean timeout = isTimeoutException(cause);
Expand All @@ -259,17 +267,17 @@ public TransactionInfo getTransactionInfo() {
}
case BeginFailure:
succeed = false;
failureHandler.onBeginFailure(e.getTransaction(), cause);
failureHandler.onBeginFailure(globalTransaction, cause);
throw cause;
case CommitFailure:
succeed = false;
failureHandler.onCommitFailure(e.getTransaction(), cause);
failureHandler.onCommitFailure(globalTransaction, cause);
throw cause;
case RollbackFailure:
failureHandler.onRollbackFailure(e.getTransaction(), e.getOriginalException());
failureHandler.onRollbackFailure(globalTransaction, e.getOriginalException());
throw e.getOriginalException();
case Rollbacking:
failureHandler.onRollbacking(e.getTransaction(), e.getOriginalException());
failureHandler.onRollbacking(globalTransaction, e.getOriginalException());
if (timeout) {
throw cause;
} else {
Expand Down