From 59dd6d090532141040367c25646621d2dc9c78f0 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 24 May 2015 20:06:13 +0300 Subject: [PATCH] Raft fix --- .../protocol/dynamic_node_id_server/distributed/raft_core.hpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/distributed/raft_core.hpp b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/distributed/raft_core.hpp index 97a92f70aa..3066d8da88 100644 --- a/libuavcan/include/uavcan/protocol/dynamic_node_id_server/distributed/raft_core.hpp +++ b/libuavcan/include/uavcan/protocol/dynamic_node_id_server/distributed/raft_core.hpp @@ -642,6 +642,8 @@ private: */ if (request.term > persistent_state_.getCurrentTerm()) { + switchState(ServerStateFollower); // Our term is stale, so we can't serve as leader + int res = persistent_state_.setCurrentTerm(request.term); if (res < 0) { @@ -679,6 +681,7 @@ private: if (response.vote_granted) { + switchState(ServerStateFollower); // Avoiding race condition when Candidate registerActivity(); // This is necessary to avoid excessive elections const int res = persistent_state_.setVotedFor(request.getSrcNodeID());