@@ -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 (" \n A 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 (" \n A 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