From 6bff9999fc6e7c0b6a95c4e0c6f273201aa0c0cc Mon Sep 17 00:00:00 2001 From: dutor <440396+dutor@users.noreply.github.com> Date: Thu, 13 Apr 2023 16:34:30 +0800 Subject: [PATCH] Fixed graphd startup issue --- src/graph/service/GraphServer.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/graph/service/GraphServer.cpp b/src/graph/service/GraphServer.cpp index 9f211dae343..0529d30314b 100644 --- a/src/graph/service/GraphServer.cpp +++ b/src/graph/service/GraphServer.cpp @@ -66,13 +66,23 @@ bool GraphServer::start() { } catch (const std::exception &e) { FLOG_ERROR("Exception thrown while starting the graph RPC server: %s", e.what()); } - serverStatus_.store(STATUS_STOPPED); + { + std::unique_lock lkStop(muStop_); + serverStatus_.store(STATUS_STOPPED); + cvStop_.notify_one(); + } FLOG_INFO("nebula-graphd on %s:%d has been stopped", localHost_.host.c_str(), localHost_.port); }); while (serverStatus_ == STATUS_UNINITIALIZED) { - std::this_thread::sleep_for(std::chrono::microseconds(100)); + std::this_thread::sleep_for(std::chrono::microseconds(1000)); + } + // In case `thriftServer_->serve()` fails, we wait a short while + std::this_thread::sleep_for(std::chrono::microseconds(1000)); + if (serverStatus_ != STATUS_RUNNING) { + return false; } + return true; } @@ -89,10 +99,8 @@ void GraphServer::waitUntilStop() { void GraphServer::notifyStop() { std::unique_lock lkStop(muStop_); - if (serverStatus_ == STATUS_RUNNING) { - serverStatus_ = STATUS_STOPPED; - cvStop_.notify_one(); - } + serverStatus_ = STATUS_STOPPED; + cvStop_.notify_one(); } // Stop the server.