aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar twerth <twerth@google.com>2018-07-18 08:08:01 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-18 08:09:31 -0700
commit20500d3b5ee50ddfac4b94516542e0739c26c425 (patch)
tree0bba43dea40fc0e720dece755d5795d7a0b05882 /src/main/cpp
parent5fe7ed0f6ddb600e86c32b2a52c7f094418f1afb (diff)
Fix race condition between server startup and command port reading.
RELNOTES: None PiperOrigin-RevId: 205079775
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/blaze.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index c84c6d4389..5813619b68 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -792,6 +792,13 @@ static void StartServerAndConnect(const WorkspaceLayout *workspace_layout,
string server_dir =
blaze_util::JoinPath(globals->options->output_base, "server");
+ // Delete the old command_port file if it already exists. Otherwise we might
+ // run into the race condition that we read the old command_port file before
+ // the new server has written the new file and we try to connect to the old
+ // port, run into a timeout and try again.
+ (void)blaze_util::UnlinkPath(
+ blaze_util::JoinPath(server_dir, "command_port"));
+
// The server dir has the socket, so we don't allow access by other
// users.
if (!blaze_util::MakeDirectories(server_dir, 0700)) {