From eb56ba363758b58516c5043080af13bbdc598be1 Mon Sep 17 00:00:00 2001 From: computezrmle <57127745+computezrmle@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:28:56 +0100 Subject: [PATCH 1/2] Heartbeat checks deal with time leaps --- samples/vboxwrapper/vboxwrapper.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 9f15ee68ae..51f250187f 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -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; @@ -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; @@ -1079,10 +1081,24 @@ int main(int argc, char** argv) { // 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; + } } } } From d08ad6a980a0fc5d5cdb92de918be8faaaa3c4aa Mon Sep 17 00:00:00 2001 From: computezrmle <57127745+computezrmle@users.noreply.github.com> Date: Tue, 29 Oct 2024 17:00:06 +0100 Subject: [PATCH 2/2] Update vboxwrapper.cpp --- samples/vboxwrapper/vboxwrapper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 51f250187f..f2392a2916 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -1079,8 +1079,6 @@ 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 { // Timestamps are not always monotonuous @@ -1111,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; } }