Skip to content

Commit

Permalink
Merge pull request #5866 from computezrmle/heartbeat_checks_deal_with…
Browse files Browse the repository at this point in the history
…_time_leaps

Heartbeat checks deal with time leaps
  • Loading branch information
AenBleidd authored Oct 30, 2024
2 parents 96370db + d08ad6a commit 3e29eae
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions samples/vboxwrapper/vboxwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ int main(int argc, char** argv) {
double timeout = 0.0;
bool report_net_usage = false;
bool initial_heartbeat_check = true;
int backtoback_heartbeat_failure = 1;
double net_usage_timer = 600;
int vm_image = 0;
unsigned long vm_exit_code = 0;
Expand Down Expand Up @@ -1050,8 +1051,9 @@ int main(int argc, char** argv) {
boinc_finish(EXIT_ABORTED_BY_CLIENT);
}
if (pVM->heartbeat_filename.size()) {
int backtoback = 3;

if (elapsed_time >= (last_heartbeat_elapsed_time + pVM->minimum_heartbeat_interval)) {
if (elapsed_time >= (last_heartbeat_elapsed_time + pVM->minimum_heartbeat_interval/backtoback)) {

int return_code = BOINC_SUCCESS;
bool should_exit = false;
Expand All @@ -1077,12 +1079,24 @@ int main(int argc, char** argv) {

if (heartbeat_stat.st_mtime > last_heartbeat_mod_time) {
// Heartbeat successful
last_heartbeat_mod_time = heartbeat_stat.st_mtime;
last_heartbeat_elapsed_time = elapsed_time;
backtoback_heartbeat_failure = 1;
} else {
vboxlog_msg("VM Heartbeat file specified, but missing heartbeat.");
return_code = ERR_TIMEOUT;
should_exit = true;
// Timestamps are not always monotonuous
// or in sync between guest and host
// e.g. after a suspend/resume
// or when local time switches between
// normal time and DST
//
// Instead of fiddling around with complex checks
// simply count backtoback inconsistencies
//
if (backtoback_heartbeat_failure < backtoback) {
backtoback_heartbeat_failure++;
} else {
vboxlog_msg("VM Heartbeat file specified, but missing heartbeat.");
return_code = ERR_TIMEOUT;
should_exit = true;
}
}
}
}
Expand All @@ -1095,6 +1109,8 @@ int main(int argc, char** argv) {
boinc_finish(return_code);
}

last_heartbeat_mod_time = heartbeat_stat.st_mtime;
last_heartbeat_elapsed_time = elapsed_time;
initial_heartbeat_check = false;
}
}
Expand Down

0 comments on commit 3e29eae

Please sign in to comment.