Skip to content

Commit

Permalink
added timeout to raft initialization
Browse files Browse the repository at this point in the history
Signed-off-by: eolesinski <[email protected]>
Co-authored-by: Michael Maurer <[email protected]>
  • Loading branch information
2 people authored and HalosGhost committed Jul 25, 2024
1 parent 57e390a commit fb29b84
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/util/raft/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,20 @@ namespace cbdc::raft {

m_log->info("Waiting for raft initialization");
static constexpr auto wait_time = std::chrono::milliseconds(100);
static constexpr auto timeout = std::chrono::seconds(30);

auto start_time = std::chrono::steady_clock::now();

while(!m_raft_instance->is_initialized()) {
std::this_thread::sleep_for(wait_time);
auto elapsed_time = std::chrono::steady_clock::now() - start_time;

if(elapsed_time > timeout) {
m_log->error("Raft initialization timed out");
m_raft_instance->shutdown();
m_raft_instance.reset();
return false;
}
}
m_log->info("Raft initialization complete");

Expand Down

0 comments on commit fb29b84

Please sign in to comment.