ivandika3 opened a new pull request, #1650:
URL: https://github.com/apache/ratis/pull/1650

   ## What changes were proposed in this pull request?
   
   Fix the "Stale AppendEntries success after a higher-term vote can let an old 
leader acknowledge an entry absent from the next leader" reported in Specula.
   
   In `RaftServerImpl#appendEntriesAsync`, the `currentTerm` is retrieved once 
under the `RaftServerImpl` lock. This `currentTerm` is also reused to the reply 
term for the asynchronous successful AppendEntries reply.
   
   However, there can be a state change between the synchronized block and the 
reply completion. For example, an election can happen in between which 
increases the server current term. This means that the previous `currentTerm` 
at the start of the `AppendEntries` is not valid anymore.
   
   Possible interleavings taken from the Specula output
   1. Old leader s2 (term 2) appends client entry (t:2, i:1) and sends it to 
follower s3 via GrpcLogAppender.
   1. s3 accepts the AppendEntries and registers the in-flight append (the 
window between the synchronized block and state.getLog().append(entries)).
   1. s3 grants and persists a higher-term vote to candidate s1 — before the 
append completes, so s3's last entry is still empty and s1 looks up-to-date.
   1. the physical append at s3 completes, and the stale SUCCESS (with the 
captured term 2, matchIndex 1) is returned.
   1. s1 becomes leader in term 3 without the entry; the old stream's SUCCESS 
is delivered to s2, which advances commit index to 1 and replies success to its 
client — violating the LeaderCompleteness invariant.
   
   The current solution is to return `NOT_LEADER` when the last `currenTerm` 
does not match with the previous `currentTerm`. 
   
   However, we might need to discuss it further before committing to a 
solution. For example, in 
https://antithesis.com/blog/2026/finding-bugs-in-raft-implementations/ it is 
mentioned that "The Raft paper assumes that all the operations (handling RPCs, 
client requests, elections, etc.) are atomic and don’t interleave with each 
other. Essentially, every node in the protocol is a finite-state machine" which 
Ratis does not seem to adhere to (i.e. how would Raft works in the case of 
asynchronous environment). 
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/RATIS-2644
   
   ## How was this patch tested?
   
   UT.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to