aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/blaze.cc
diff options
context:
space:
mode:
authorGravatar lberki <lberki@google.com>2017-06-06 08:54:50 -0400
committerGravatar John Cater <jcater@google.com>2017-06-06 09:51:14 -0400
commita94aa636b5f1462ceaf86bc566a96746b21f18dd (patch)
tree4848a375c8a888c48a1d5dc22bce032dbacb9a9d /src/main/cpp/blaze.cc
parentf3753580583ab025eceaaf2b76e61b7b99be2e39 (diff)
Fix a bunch of issues related to server startup/shutdown:
- Only try to communicate with the server if it passes verification (i.e. the indicated PID exists and its start time is correct) - Use only one thread to delete files on exit - Don't set restart reason to NEW_VERSION unless there is an existing server RELNOTES: None. PiperOrigin-RevId: 158131470
Diffstat (limited to 'src/main/cpp/blaze.cc')
-rw-r--r--src/main/cpp/blaze.cc38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index 438253422a..0b22226aac 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -711,7 +711,7 @@ static void SetRestartReasonIfNotSet(RestartReason restart_reason) {
}
}
-// Starts up a new server and connects to it. Exits if it didn't work not.
+// Starts up a new server and connects to it. Exits if it didn't work out.
static void StartServerAndConnect(const WorkspaceLayout *workspace_layout,
BlazeServer *server) {
string server_dir =
@@ -1077,9 +1077,9 @@ static void EnsureCorrectRunningVersion(BlazeServer *server) {
globals->options->install_base)) {
if (server->Connected()) {
server->KillRunningServer();
+ globals->restart_reason = NEW_VERSION;
}
- globals->restart_reason = NEW_VERSION;
blaze_util::UnlinkPath(installation_path);
if (!SymlinkDirectories(globals->options->install_base,
installation_path)) {
@@ -1444,6 +1444,16 @@ bool GrpcBlazeServer::Connect() {
return false;
}
+ pid_t server_pid = GetServerPid(server_dir);
+ if (server_pid < 0) {
+ return false;
+ }
+
+ if (!VerifyServerProcess(server_pid, globals->options->output_base,
+ globals->options->install_base)) {
+ return false;
+ }
+
std::shared_ptr<grpc::Channel> channel(
grpc::CreateChannel(port, grpc::InsecureChannelCredentials()));
std::unique_ptr<command_server::CommandServer::Stub> client(
@@ -1455,29 +1465,7 @@ bool GrpcBlazeServer::Connect() {
this->client_ = std::move(client);
connected_ = true;
-
- globals->server_pid = GetServerPid(server_dir);
- if (globals->server_pid <= 0) {
- fprintf(stderr,
- "Can't get PID of existing server (server dir=%s). "
- "Shutting it down and starting a new one...\n",
- server_dir.c_str());
- // This means that we have a server we could connect to but without a PID
- // file, which in turn means that something went wrong before. Kill the
- // server so that we can start with as clean a slate as possible. This may
- // happen if someone (e.g. a client or server that's very old and uses an
- // AF_UNIX socket instead of gRPC) deletes the server.pid.txt file.
- KillRunningServer();
- // Then wait until it actually dies
- do {
- auto next_attempt_time(std::chrono::system_clock::now() +
- std::chrono::milliseconds(1000));
- std::this_thread::sleep_until(next_attempt_time);
- } while (TryConnect(client_.get()));
-
- return false;
- }
-
+ globals->server_pid = server_pid;
return true;
}