RATIS-2719. SegmentedRaftLog.close may deadlock with the cache eviction thread. - #1617
Merged
Merged
Conversation
amaliujia
approved these changes
Oct 1, 2026
szetszwo
approved these changes
Oct 1, 2026
szetszwo
left a comment
Contributor
There was a problem hiding this comment.
+1 the change looks good.
Contributor
|
@slfan1989 , thanks for working on this! @amaliujia , thanks also for reviewing this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
SegmentedRaftLog.close()acquires the write lock before callingcacheEviction.close(), which interrupts the cache eviction thread and waits for it to terminate usingThread.join().If the eviction thread is waiting for the same write lock, a deadlock occurs:
the closing thread waits for the eviction thread to terminate, while the eviction thread waits for the closing thread to release the lock.
Interrupting the eviction thread does not resolve this because it acquires the lock using
lock().This PR moves
cacheEviction.close()before acquiring the write lock, so the closing thread waits for the eviction thread to terminate without holding the lock. The eviction thread can therefore complete its current operation and exit before the cache is closed.What is the link to the Apache JIRA
RATIS-2719. SegmentedRaftLog.close may deadlock with the cache eviction thread.
This issue was identified while investigating a timeout in
TestSegmentedRaftLog.testAppendAndRollduring a CI run. The test timed out after 100 seconds, and the following stack trace shows that the test thread was waiting inThread.join()while closing the cache eviction thread:https://github.com/apache/ratis/actions/runs/36554382990/job/109359915576?pr=1615
How was this patch tested?
https://github.com/slfan1989/ratis/actions/runs/36564811620