From e50e33f8f6bb7c7b9392edcd01edcbed07c3efe7 Mon Sep 17 00:00:00 2001 From: Mitsunori Komatsu Date: Wed, 16 Aug 2023 00:06:10 +0900 Subject: [PATCH] Improve `request_vote` in candidate --- lib/candidate.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/candidate.ml b/lib/candidate.ml index 27c7246..a41bc01 100644 --- a/lib/candidate.ml +++ b/lib/candidate.ml @@ -109,7 +109,6 @@ let request_vote t ~election_timer = | Error msg -> Logger.error t.logger ~loc:__LOC__ (sprintf "request_vote failed. error:[%s]" msg); - (* TODO: Revisit here *) Lwt_list.map_p Lwt.return [] @@ -174,6 +173,8 @@ let request_handlers t ~election_timer = let collect_votes t ~election_timer ~vote_request = let%lwt responses = vote_request in + (* `request_vote` returns an empty list when an error occurs. + It results in n = 1 and doesn't reach the majority *) let%lwt n = Lwt.return (List.fold_left ~init:1 (* Implicitly voting for myself *) @@ -251,7 +252,7 @@ let run ~conf ~apply_log ~state = let election_timer_thread = Timer.start election_timer ~on_stop:(fun () -> Lwt.wakeup stopper (); - Lwt.cancel vote_request + Lwt.cancel received_votes ) in let next () = Lwt.return (next_mode t) in