Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added timeout to raft initialization #290

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading