Skip to content

Commit

Permalink
fix: work around for connection hang when network down (#1352)
Browse files Browse the repository at this point in the history
* fix: work around for connection hang when network down

* f:m

* f:n

---------

Co-authored-by: vansangpfiev <[email protected]>
  • Loading branch information
vansangpfiev and sangjanai authored Sep 30, 2024
1 parent ea74a70 commit 1069b89
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions engine/controllers/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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
Expand Down

0 comments on commit 1069b89

Please sign in to comment.