in src/limitless/limitless_router_monitor.cc [106:141]
void LimitlessRouterMonitor::Run(SQLHENV henv, SQLHDBC conn, SQLTCHAR *connection_string, SQLSMALLINT connection_string_len, int host_port) {
SQLSMALLINT out_connection_string_len; // unused
while (!this->stopped) {
std::this_thread::sleep_for(std::chrono::milliseconds(this->interval_ms));
if (conn == SQL_NULL_HANDLE || !OdbcHelper::CheckConnection(conn)) {
// OdbcHelper::CheckConnection failed on a pre-existing handle, so free it
OdbcHelper::Cleanup(SQL_NULL_HENV, conn, SQL_NULL_HSTMT);
SQLRETURN rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &conn);
if (!OdbcHelper::CheckResult(rc, "LimitlessRouterMonitor: SQLAllocHandle failed", conn, SQL_HANDLE_DBC)) {
break; // this is a fatal error; stop monitoring
}
rc = SQLDriverConnect(conn, nullptr, connection_string, connection_string_len, nullptr, 0, &out_connection_string_len, SQL_DRIVER_NOPROMPT);
if (!SQL_SUCCEEDED(rc)) {
OdbcHelper::Cleanup(SQL_NULL_HENV, conn, SQL_NULL_HSTMT);
// wait the full interval and then try to reconnect
continue;
} // else, connection was successful, proceed below
}
std::vector<HostInfo> new_limitless_routers = LimitlessQueryHelper::QueryForLimitlessRouters(conn, host_port);
// LimitlessQueryHelper::QueryForLimitlessRouters will return an empty vector on an error
// if it was a connection error, then the next loop will catch it and attempt to reconnect
if (!new_limitless_routers.empty()) {
std::lock_guard<std::mutex> guard(*(this->limitless_routers_mutex));
*(this->limitless_routers) = new_limitless_routers;
}
}
OdbcHelper::Cleanup(henv, conn, SQL_NULL_HSTMT);
}