diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index 8a28f6d9e..3925ad502 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -69,15 +69,30 @@ 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) { - 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 an 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 = 10; + while (!done && retry--) { + std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 10); } } #endif