aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar Lukacs Berki <lberki@google.com>2016-11-15 15:45:58 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-11-15 15:59:25 +0000
commit5570bcca4e2d99570eeda688fb0ae8a52ada1659 (patch)
treefa63ece4db9049356dc08a695a0699361a6ac1ce /src/main/cpp
parent2d1d492db1f3c354a34850a85a3f51366dba92b7 (diff)
Refactor the logic that is used to retry client timeouts a bit so that the attempts take into account the fact that failed connection attempts can take a long time.
-- MOS_MIGRATED_REVID=139199883
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/blaze.cc23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/main/cpp/blaze.cc b/src/main/cpp/blaze.cc
index b69586012a..7b3d893a2f 100644
--- a/src/main/cpp/blaze.cc
+++ b/src/main/cpp/blaze.cc
@@ -812,26 +812,31 @@ static void StartServerAndConnect(BlazeServer *server) {
BlazeServerStartup* server_startup;
StartServer(&server_startup);
- // Give the server one minute to start up.
- for (int ii = 0; ii < 600; ++ii) {
- // 60s; enough time to connect with debugger
+
+ // Give the server two minutes to start up. That's enough to connect with a
+ // debugger.
+ auto try_until_time(
+ std::chrono::system_clock::now() + std::chrono::seconds(120));
+ bool had_to_wait = false;
+ while (std::chrono::system_clock::now() < try_until_time) {
+ auto next_attempt_time(
+ std::chrono::system_clock::now() + std::chrono::milliseconds(100));
if (server->Connect()) {
- if (ii && !globals->options->client_debug) {
+ if (had_to_wait && !globals->options->client_debug) {
fputc('\n', stderr);
fflush(stderr);
}
delete server_startup;
return;
}
+
+ had_to_wait = true;
if (!globals->options->client_debug) {
fputc('.', stderr);
fflush(stderr);
}
- struct timespec ts;
- ts.tv_sec = 0;
- ts.tv_nsec = 100 * 1000 * 1000;
- nanosleep(&ts, NULL);
+ std::this_thread::sleep_until(next_attempt_time);
if (!server_startup->IsStillAlive()) {
fprintf(stderr, "\nunexpected pipe read status: %s\n"
"Server presumed dead. Now printing '%s':\n",
@@ -841,7 +846,7 @@ static void StartServerAndConnect(BlazeServer *server) {
}
}
die(blaze_exit_code::INTERNAL_ERROR,
- "\nError: couldn't connect to server after 60 seconds.");
+ "\nError: couldn't connect to server after 120 seconds.");
}
// Calls fsync() on the file (or directory) specified in 'file_path'.