Closed ye-xiaowei closed 3 weeks ago
The changes address potential deadlock issues in the ThreadId.java
file by ensuring that the lock is only unlocked if held by the current thread. Additionally, the test assertion delta in ThreadIdTest.java
has been adjusted from 10 to 20.
File Path | Change Summary |
---|---|
jraft-core/src/main/java/com/alipay/sofa/jraft/util/ThreadId.java |
Updated the finally block to check if the lock is held by the current thread before unlocking it. |
jraft-core/src/test/java/com/alipay/sofa/jraft/util/ThreadIdTest.java |
Modified the assertion delta in a test method from 10 to 20. |
Objective (Issue #1107) | Addressed | Explanation |
---|---|---|
Ensure no deadlock occurs when FSMCaller-Disruptor thread destroys Replicator while other threads wait on the lock. | ✅ | |
Validate the lock is only unlocked if held by the current thread. | ✅ |
In the realm of code so bright,
Threads dance through day and night,
Locks now held with care,
No deadlocks to ensnare,
Tests adjusted, all set right.
🎉🐇
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
@killme2008 Please take a look, and I wonder if we can just use ThreadId.unlock()
to instead this.lock.unlock()
?
Motivation:
在 ThreadId lock 和 destroy ThreadId 并发情况下,可能导致 ThreadId 锁不释放
Modification:
取消判断 ThreadId 是否 destroy 来释放锁,而是只要持有就释放。因为在 onError 中可能释放锁,需要判断
isHeldByCurrentThread()
是否持有来释放锁Result:
Fixes #1107
Summary by CodeRabbit
Bug Fixes
Tests