From 250bf5bb7479d00ff4567490e555ec9bd9a7a4ee Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 27 Sep 2024 18:57:51 +0700 Subject: [PATCH 1/3] fix: work around for connection hang when network down --- engine/controllers/command_line_parser.cc | 27 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 8a28f6d9e..4cd051fc8 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -72,12 +72,27 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { // Check new update, only check for stable release for now #ifdef CORTEX_CPP_VERSION if (cml_data_.check_upd) { - if (auto latest_version = commands::CheckNewUpdate(commands::kTimeoutCheckUpdate); - latest_version.has_value() && *latest_version != CORTEX_CPP_VERSION) { - CLI_LOG("\nA new release of cortex is available: " - << CORTEX_CPP_VERSION << " -> " << *latest_version); - CLI_LOG("To upgrade, run: " << commands::GetRole() - << commands::GetCortexBinary() << " update"); + // TODO(sang) find a better way to handle + // This is a extremely ungly way to deal with connection + // hang when network down + std::atomic done = false; + std::thread t([&]() { + if (auto latest_version = + commands::CheckNewUpdate(commands::kTimeoutCheckUpdate); + latest_version.has_value() && *latest_version != CORTEX_CPP_VERSION) { + CLI_LOG("\nA new release of cortex is available: " + << CORTEX_CPP_VERSION << " -> " << *latest_version); + CLI_LOG("To upgrade, run: " << commands::GetRole() + << commands::GetCortexBinary() + << " update"); + } + done = true; + }); + // Do not wait for http connection timeout + t.detach(); + int retry = 5; + while (!done && retry--) { + std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 5); } } #endif From e61b234d9b60086d2837ac33b05ee7349cd6fbf6 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 27 Sep 2024 19:00:52 +0700 Subject: [PATCH 2/3] f:m --- engine/controllers/command_line_parser.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 4cd051fc8..ee7064edf 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -73,7 +73,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { #ifdef CORTEX_CPP_VERSION if (cml_data_.check_upd) { // TODO(sang) find a better way to handle - // This is a extremely ungly way to deal with connection + // This is an extremely ungly way to deal with connection // hang when network down std::atomic done = false; std::thread t([&]() { @@ -90,9 +90,9 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { }); // Do not wait for http connection timeout t.detach(); - int retry = 5; + int retry = 10; while (!done && retry--) { - std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 5); + std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 10); } } #endif From 73246d0e984fd4a93a8f027165e464bcea078e8a Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 27 Sep 2024 19:01:44 +0700 Subject: [PATCH 3/3] f:n --- engine/controllers/command_line_parser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index ee7064edf..3925ad502 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -69,7 +69,7 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { return true; } - // Check new update, only check for stable release for now + // Check new update #ifdef CORTEX_CPP_VERSION if (cml_data_.check_upd) { // TODO(sang) find a better way to handle