diff --git a/server/raft.go b/server/raft.go index dad6b902c21..d5bcc0c5eee 100644 --- a/server/raft.go +++ b/server/raft.go @@ -3184,6 +3184,13 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) { return } + if ae.term < n.term { + // ignore + n.debug("ignoring ae req from a leader with term %d which is less than ours", ae.term) + n.Unlock() + return + } + // Scratch buffer for responses. var scratch [appendEntryResponseLen]byte arbuf := scratch[:] @@ -3294,12 +3301,7 @@ func (n *raft) processAppendEntry(ae *appendEntry, sub *subscription) { n.debug("Term higher than ours and we are not a follower: %v, stepping down to %q", n.State(), ae.leader) n.stepdownLocked(ae.leader) } - } else if ae.term < n.term { - // ignore - n.debug("ignoring ae req from a leader with term %d which is less than ours") - return } - // FIX: we need to handle if term is less than ours as well, we should be ignoring the entry // BUG: leader was being updated even if the leader's term was out of date (behind ours) if isNew && n.leader != ae.leader && n.State() == Follower {