You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "wangsansan (via GitHub)" <gi...@apache.org> on 2026/08/11 06:35:33 UTC

[I] 全局事务已提交,但是全局锁没有释放 [incubator-seata]

wangsansan opened a new issue, #8197:
URL: https://github.com/apache/incubator-seata/issues/8197

   ### Check Ahead
   
   - [x] I have searched the [issues](https://github.com/seata/seata/issues) of this repository and believe that this is not a duplicate.
   
   - [ ] I am willing to try to fix this bug myself.
   
   
   ### Ⅰ. Issue Description
   
   1. seata2.4,AT模式,lock_model、lock_store_mode、session_store_mode 都是file
   2. 生产环境一直提示获取锁超时,通过seata server日志发现,锁被一个全局事务持有,后续发现该事务早就提交了。
   3. 
   
   <img width="1053" height="90" alt="Image" src="https://github.com/user-attachments/assets/0e141a17-1b2c-4d78-b42f-4ac56ccbe606" />
   
   ### Ⅱ. Describe what happened
   
   把全量日志让codex分析了下。codex给的结论是:
   
   <img width="734" height="519" alt="Image" src="https://github.com/user-attachments/assets/caf8c1c3-fb78-41b7-b0b7-cb2ce730fb94" />
   
   ### Ⅲ. Describe what you expected to happen
   
   _No response_
   
   ### Ⅳ. How to reproduce it (as minimally and precisely as possible)
   
   _No response_
   
   ### Ⅴ. Anything else we need to know?
   
   _No response_
   
   ### Ⅵ. Environment
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [I] 全局事务已提交,但是全局锁没有释放 [incubator-seata]

Posted by "wangsansan (via GitHub)" <gi...@apache.org>.
wangsansan commented on issue #8197:
URL: https://github.com/apache/incubator-seata/issues/8197#issuecomment-5249883177

   09:51:26.142 ERROR
   java.util.ConcurrentModificationException
   at java.util.ArrayList$Itr.checkForComodification
   at org.apache.seata.server.storage.file.lock.FileLockManager.releaseGlobalSessionLock(FileLockManager.java:48)
   at org.apache.seata.server.session.GlobalSession.clean(GlobalSession.java:305)
   at org.apache.seata.server.coordinator.DefaultCore.lambda$commit$0(DefaultCore.java:234)
   
   
   09:51:27.926 Committing global transaction is successfully done
   xid = 10.228.9.187:8091:847484980191724603
   
   
   
   codex说bug在:
   `List<BranchSession> branchSessions = globalSession.getBranchSessions();
   for (BranchSession branchSession : branchSessions) {
       ...
   }`
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [I] 全局事务已提交,但是全局锁没有释放 [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes commented on issue #8197:
URL: https://github.com/apache/incubator-seata/issues/8197#issuecomment-5249959256

   This suggests that a new branch was registered asynchronously while the client was resolving the transaction.
   
   However, both branch registration and transaction commit are wrapped with SessionHolder.lockAndExecute, which acquires the lock at the GlobalSession level. In theory, these operations should therefore be mutually exclusive.
   
   We need to investigate which code path is bypassing this locking mechanism and allowing concurrent access, ultimately resulting in a ConcurrentModificationException.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [I] 全局事务已提交,但是全局锁没有释放 [incubator-seata]

Posted by "funky-eyes (via GitHub)" <gi...@apache.org>.
funky-eyes closed issue #8197: 全局事务已提交,但是全局锁没有释放
URL: https://github.com/apache/incubator-seata/issues/8197


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org


Re: [I] 全局事务已提交,但是全局锁没有释放 [incubator-seata]

Posted by "Zhengcy05 (via GitHub)" <gi...@apache.org>.
Zhengcy05 commented on issue #8197:
URL: https://github.com/apache/incubator-seata/issues/8197#issuecomment-5276818193

   I looked into this issue, and the evidence points to a race between the initial commit cleanup and the scheduled async-commit worker, rather than a late branch registration.
   
   For an AT transaction, `DefaultCore.commit()` changes the global status to `AsyncCommitting` before `globalSession.clean()` has finished releasing all file locks. The scheduled `handleAsyncCommitting()` task can observe that status and call `doGlobalCommit(..., true)` without acquiring the same `GlobalSession` lock.
   
   The async commit path then removes committed `BranchSession` objects while `FileLockManager.releaseGlobalSessionLock()` is iterating the same `ArrayList`, which explains the `ConcurrentModificationException`.
   
   This also explains the residual lock: while the status is `AsyncCommitting`, `GlobalSession.unlockBranch()` assumes that the initial global cleanup has already released the lock and skips the per-branch unlock. If that branch is removed after the initial cleanup aborts, subsequent cleanup can no longer find it, leaving the entry in `FileLocker.LOCK_MAP`.
   
   I suggest serializing the scheduled async-commit handling with the same `GlobalSession` lock and rechecking the status inside the lock. A snapshot-only change in `FileLockManager` would avoid the iterator exception but would not guarantee that a concurrently removed branch has been unlocked.
   
   Below is my understanding of the timing of this bug。
   ```mermaid
   sequenceDiagram
       autonumber
       participant A as Commit Thread A
       participant GS as GlobalSession
       participant BL as branchSessions (ArrayList)
       participant B as Async Commit Thread B
   
       A->>GS: Acquire GlobalSession lock
       activate A
       A->>GS: Change status to AsyncCommitting
       Note over A,GS: Global lock cleanup has not finished
   
       B->>GS: Scheduled task observes AsyncCommitting
       activate B
       Note over B,GS: Thread B does not acquire the GlobalSession lock
   
       A->>BL: Iterate branches to release global locks
       loop For each BranchSession
           A->>BL: Read next branch
       end
   
       B->>B: Commit branch successfully
       B->>BL: Remove committed BranchSession
   
       BL--xA: Iterator detects concurrent modification
       Note over A,BL: ConcurrentModificationException
       deactivate A
   
       Note over GS,BL: Cleanup stops before all global locks are released
       deactivate B
   ```
   Chinese Version
   ```mermaid
   sequenceDiagram
       autonumber
       participant A as 提交线程 A
       participant GS as GlobalSession
       participant BL as branchSessions(ArrayList)
       participant B as 异步提交线程 B
   
       A->>GS: 获取 GlobalSession 锁
       activate A
       A->>GS: 将状态修改为 AsyncCommitting
       Note over A,GS: 此时全局锁清理尚未完成
   
       B->>GS: 定时任务发现 AsyncCommitting 状态
       activate B
       Note over B,GS: 线程 B 没有获取 GlobalSession 锁
   
       A->>BL: 遍历分支并释放全局锁
       loop 遍历每个 BranchSession
           A->>BL: 读取下一个分支
       end
   
       B->>B: 分支提交成功
       B->>BL: 删除已提交的 BranchSession
   
       BL--xA: 迭代器检测到并发修改
       Note over A,BL: 抛出 ConcurrentModificationException
       deactivate A
   
       Note over GS,BL: 清理被中断,部分全局锁未能释放
       deactivate B
   ```
   
   If this direction looks good, I’d like to work on it and add a concurrency regression test.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org