1
0

Fixed polling issues when a server is erroring out and also peering the right id

This commit is contained in:
Emagi 2024-12-02 20:01:21 -05:00
parent 140d58d0da
commit 405e43f672
2 changed files with 156 additions and 154 deletions

View File

@ -511,11 +511,8 @@ void HTTPSClientPool::pollPeerHealth(const std::string& server, const std::strin
LogWrite(PEERING__ERROR, 0, "Peering", "%s: Error finding peer %s:%s.", __FUNCTION__, server.c_str(), port.c_str());
}
else {
auto client = getOrCreateClient(id, port, server + ":" + port);
auto client = getOrCreateClient(id, server, port);
int16 interval = pollingInterval;
while (running.load()) {
interval++;
if (interval > pollingInterval) {
HealthStatus curStatus = peer_manager.getPeerStatus(server, web_worldport);
id = peer_manager.isPeer(server, web_worldport);
try {
@ -547,7 +544,7 @@ void HTTPSClientPool::pollPeerHealth(const std::string& server, const std::strin
net.SetPrimary(false);
}
}
else if(!peer_manager.hasPrimary() && peer_primary) {
else if (!peer_manager.hasPrimary() && peer_primary) {
peer_manager.setPrimary(id);
}
@ -656,13 +653,9 @@ void HTTPSClientPool::pollPeerHealth(const std::string& server, const std::strin
}
}
LogWrite(PEERING__ERROR, 0, "Peering", "%s: ERROR POLLING %s:%s reason: %s", __FUNCTION__, server.c_str(), port.c_str(), e.what() ? e.what() : "??");
std::this_thread::sleep_for(std::chrono::milliseconds(400));
}
interval = 0;
}
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
}
void HTTPSClientPool::pollPeerHealthData(auto client, const std::string& id, const std::string& server, const std::string& port) {
@ -724,15 +717,19 @@ void HTTPSClientPool::startPolling() {
std::async(std::launch::async, [this, server, port]() {
try {
pollPeerHealth(server, port);
} catch (const std::exception& e) {
}
catch (const std::exception& e) {
LogWrite(PEERING__DEBUG, 1, "Peering", "Exception in pollPeerHealth for %s:%s: %s", server.c_str(), port.c_str(), e.what());
} catch (...) {
}
catch (...) {
LogWrite(PEERING__DEBUG, 1, "Peering", "Unknown exception in pollPeerHealth for %s:%s.", server.c_str(), port.c_str());
}
});
} catch (const std::exception& e) {
}
catch (const std::exception& e) {
LogWrite(PEERING__DEBUG, 1, "Peering", "Failed to start async task for %s:%s: %s", server.c_str(), port.c_str(), e.what());
} catch (...) {
}
catch (...) {
LogWrite(PEERING__DEBUG, 1, "Peering", "Unknown exception when starting async task for %s:%s.", server.c_str(), port.c_str());
}
}

View File

@ -634,8 +634,13 @@ ThreadReturnType AchievmentLoad (void* tmp)
ThreadReturnType StartPeerPoll (void* tmp)
{
while( RunLoops )
{
LogWrite(WORLD__WARNING, 0, "Thread", "Start Polling...");
peer_https_pool.startPolling();
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
THREAD_RETURN(NULL);
}