Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 1069b89

Browse files
fix: work around for connection hang when network down (#1352)
* fix: work around for connection hang when network down * f:m * f:n --------- Co-authored-by: vansangpfiev <sang@jan.ai>
1 parent ea74a70 commit 1069b89

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

engine/controllers/command_line_parser.cc

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,30 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
6969
return true;
7070
}
7171

72-
// Check new update, only check for stable release for now
72+
// Check new update
7373
#ifdef CORTEX_CPP_VERSION
7474
if (cml_data_.check_upd) {
75-
if (auto latest_version = commands::CheckNewUpdate(commands::kTimeoutCheckUpdate);
76-
latest_version.has_value() && *latest_version != CORTEX_CPP_VERSION) {
77-
CLI_LOG("\nA new release of cortex is available: "
78-
<< CORTEX_CPP_VERSION << " -> " << *latest_version);
79-
CLI_LOG("To upgrade, run: " << commands::GetRole()
80-
<< commands::GetCortexBinary() << " update");
75+
// TODO(sang) find a better way to handle
76+
// This is an extremely ungly way to deal with connection
77+
// hang when network down
78+
std::atomic<bool> done = false;
79+
std::thread t([&]() {
80+
if (auto latest_version =
81+
commands::CheckNewUpdate(commands::kTimeoutCheckUpdate);
82+
latest_version.has_value() && *latest_version != CORTEX_CPP_VERSION) {
83+
CLI_LOG("\nA new release of cortex is available: "
84+
<< CORTEX_CPP_VERSION << " -> " << *latest_version);
85+
CLI_LOG("To upgrade, run: " << commands::GetRole()
86+
<< commands::GetCortexBinary()
87+
<< " update");
88+
}
89+
done = true;
90+
});
91+
// Do not wait for http connection timeout
92+
t.detach();
93+
int retry = 10;
94+
while (!done && retry--) {
95+
std::this_thread::sleep_for(commands::kTimeoutCheckUpdate / 10);
8196
}
8297
}
8398
#endif

0 commit comments

Comments
 (0)