From efefd177702a058c3fd488d2a5b9fe3acadb31f1 Mon Sep 17 00:00:00 2001
From: Dmego <dmeago@gmail.com>
Date: Wed, 10 Mar 2021 10:12:48 +0800
Subject: [PATCH] bugfix: set time threshold for transactions in committing
 state (#3560)

---
 changes/1.5.0.md                                           | 3 +++
 changes/en-us/1.5.0.md                                     | 3 +++
 .../io/seata/server/coordinator/DefaultCoordinator.java    | 7 ++++++-
 .../main/java/io/seata/server/session/GlobalSession.java   | 6 +++---
 .../server/storage/db/session/DataBaseSessionManager.java  | 2 +-
 .../server/storage/redis/session/RedisSessionManager.java  | 2 +-
 6 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/changes/1.5.0.md b/changes/1.5.0.md
index 136ccc340..03d86df61 100644
--- a/changes/1.5.0.md
+++ b/changes/1.5.0.md
@@ -43,6 +43,8 @@ Seata 鏄竴娆惧紑婧愮殑鍒嗗竷寮忎簨鍔¤В鍐虫柟妗堬紝鎻愪緵楂樻€ц兘鍜岀畝鍗�
   - [[#3481](https://github.com/seata/seata/pull/3481)] 淇褰� consul client 鑾峰彇闆嗙兢淇℃伅鎶ラ敊鏃朵細瀵艰嚧鍒锋柊浠诲姟涓柇
   - [[#3491](https://github.com/seata/seata/pull/3491)] 淇README.md鏂囦欢涓殑鎷煎啓閿欒
   - [[#3531](https://github.com/seata/seata/pull/3531)] 淇RedisTransactionStoreManager璇诲彇brachTransaction涓殑NPE
+  - [[#3500](https://github.com/seata/seata/pull/3500)] 淇 oracle 鍜� postgreSql 涓嶈兘鏌ヨ鍑� column info 鐨勯棶棰�
+  - [[#3560](https://github.com/seata/seata/pull/3560)] 淇 Committing 鐘舵€佺殑浜嬪姟娌℃湁鏃堕棿闃堝€奸棶棰�
   - [[#3555](https://github.com/seata/seata/pull/3555)] 閫氳繃setBytes浠f浛setBlob锛岄伩鍏嶉珮鐗堟湰jdbc椹卞姩宸ヤ綔寮傚父
   - [[#3540](https://github.com/seata/seata/pull/3540)] 淇server鍙戝竷鎵撳寘鏃剁己澶辨枃浠�
 
@@ -106,6 +108,7 @@ Seata 鏄竴娆惧紑婧愮殑鍒嗗竷寮忎簨鍔¤В鍐虫柟妗堬紝鎻愪緵楂樻€ц兘鍜岀畝鍗�
   - [github-ganyu](https://github.com/github-ganyu)
   - [xuande](https://github.com/xuande)
   - [tanggen](https://github.com/tanggen)
+  - [dmego](https://github.com/dmego)
 
 
 鍚屾椂锛屾垜浠敹鍒颁簡绀惧尯鍙嶉鐨勫緢澶氭湁浠峰€肩殑issue鍜屽缓璁紝闈炲父鎰熻阿澶у銆�
diff --git a/changes/en-us/1.5.0.md b/changes/en-us/1.5.0.md
index 8232bc527..9e2e0c202 100644
--- a/changes/en-us/1.5.0.md
+++ b/changes/en-us/1.5.0.md
@@ -44,6 +44,8 @@
   - [[#3481](https://github.com/seata/seata/pull/3481)] fix seata node refresh failure because consul crash
   - [[#3491](https://github.com/seata/seata/pull/3491)] fix typo in README.md
   - [[#3531](https://github.com/seata/seata/pull/3531)] fix the NPE of RedisTransactionStoreManager when get branch transactions
+  - [[#3500](https://github.com/seata/seata/pull/3500)] fix oracle and postgreSQL can't query column info
+  - [[#3560](https://github.com/seata/seata/pull/3560)] set time threshold for transactions in committing state
   - [[#3555](https://github.com/seata/seata/pull/3555)]  do not call setBlob to invalid the jdbc exception
   - [[#3540](https://github.com/seata/seata/pull/3540)] fix server distribution missing files
 
@@ -110,6 +112,7 @@
   - [github-ganyu](https://github.com/github-ganyu)
   - [xuande](https://github.com/xuande)
   - [tanggen](https://github.com/tanggen)
+  - [dmego](https://github.com/dmego)
 
 
   Also, we receive many valuable issues, questions and advices from our community. Thanks for you all.	
diff --git a/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java b/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
index 7f289cb03..929a5a462 100644
--- a/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
+++ b/server/src/main/java/io/seata/server/coordinator/DefaultCoordinator.java
@@ -281,7 +281,7 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
         SessionHelper.forEach(rollbackingSessions, rollbackingSession -> {
             try {
                 // prevent repeated rollback
-                if (rollbackingSession.getStatus().equals(GlobalStatus.Rollbacking) && !rollbackingSession.isRollbackingDead()) {
+                if (rollbackingSession.getStatus().equals(GlobalStatus.Rollbacking) && !rollbackingSession.isDeadSession()) {
                     //The function of this 'return' is 'continue'.
                     return;
                 }
@@ -316,6 +316,11 @@ public class DefaultCoordinator extends AbstractTCInboundHandler implements Tran
         long now = System.currentTimeMillis();
         SessionHelper.forEach(committingSessions, committingSession -> {
             try {
+                // prevent repeated commit
+                if (committingSession.getStatus().equals(GlobalStatus.Committing) && !committingSession.isDeadSession()) {
+                    //The function of this 'return' is 'continue'.
+                    return;
+                }
                 if (isRetryTimeout(now, MAX_COMMIT_RETRY_TIMEOUT.toMillis(), committingSession.getBeginTime())) {
                     /**
                      * Prevent thread safety issues
diff --git a/server/src/main/java/io/seata/server/session/GlobalSession.java b/server/src/main/java/io/seata/server/session/GlobalSession.java
index 02b8a93a6..d673ced26 100644
--- a/server/src/main/java/io/seata/server/session/GlobalSession.java
+++ b/server/src/main/java/io/seata/server/session/GlobalSession.java
@@ -157,10 +157,10 @@ public class GlobalSession implements SessionLifecycle, SessionStorable {
     }
 
     /**
-     * prevent could not handle rollbacking transaction
-     * @return if true force roll back
+     * prevent could not handle committing and rollbacking transaction
+     * @return if true retry commit or roll back
      */
-    public boolean isRollbackingDead() {
+    public boolean isDeadSession() {
         return (System.currentTimeMillis() - beginTime) > (2 * 6000);
     }
 
diff --git a/server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java b/server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java
index 5f3faf5c7..f05cf1f28 100644
--- a/server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java
+++ b/server/src/main/java/io/seata/server/storage/db/session/DataBaseSessionManager.java
@@ -168,7 +168,7 @@ public class DataBaseSessionManager extends AbstractSessionManager
         if (SessionHolder.ASYNC_COMMITTING_SESSION_MANAGER_NAME.equalsIgnoreCase(taskName)) {
             return findGlobalSessions(new SessionCondition(GlobalStatus.AsyncCommitting));
         } else if (SessionHolder.RETRY_COMMITTING_SESSION_MANAGER_NAME.equalsIgnoreCase(taskName)) {
-            return findGlobalSessions(new SessionCondition(new GlobalStatus[] {GlobalStatus.CommitRetrying}));
+            return findGlobalSessions(new SessionCondition(new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committing}));
         } else if (SessionHolder.RETRY_ROLLBACKING_SESSION_MANAGER_NAME.equalsIgnoreCase(taskName)) {
             return findGlobalSessions(new SessionCondition(new GlobalStatus[] {GlobalStatus.RollbackRetrying,
                 GlobalStatus.Rollbacking, GlobalStatus.TimeoutRollbacking, GlobalStatus.TimeoutRollbackRetrying}));
diff --git a/server/src/main/java/io/seata/server/storage/redis/session/RedisSessionManager.java b/server/src/main/java/io/seata/server/storage/redis/session/RedisSessionManager.java
index 63bc5d9c8..ef6630603 100644
--- a/server/src/main/java/io/seata/server/storage/redis/session/RedisSessionManager.java
+++ b/server/src/main/java/io/seata/server/storage/redis/session/RedisSessionManager.java
@@ -166,7 +166,7 @@ public class RedisSessionManager extends AbstractSessionManager
         if (SessionHolder.ASYNC_COMMITTING_SESSION_MANAGER_NAME.equalsIgnoreCase(taskName)) {
             return findGlobalSessions(new SessionCondition(GlobalStatus.AsyncCommitting));
         } else if (SessionHolder.RETRY_COMMITTING_SESSION_MANAGER_NAME.equalsIgnoreCase(taskName)) {
-            return findGlobalSessions(new SessionCondition(new GlobalStatus[] {GlobalStatus.CommitRetrying}));
+            return findGlobalSessions(new SessionCondition(new GlobalStatus[] {GlobalStatus.CommitRetrying, GlobalStatus.Committing}));
         } else if (SessionHolder.RETRY_ROLLBACKING_SESSION_MANAGER_NAME.equalsIgnoreCase(taskName)) {
             return findGlobalSessions(new SessionCondition(new GlobalStatus[] {GlobalStatus.RollbackRetrying,
                 GlobalStatus.Rollbacking, GlobalStatus.TimeoutRollbacking, GlobalStatus.TimeoutRollbackRetrying}));
-- 
GitLab