From 1fda5cab9d18346e049cf84a9e791bbf89b7a861 Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Thu, 24 Feb 2022 15:12:40 +0000 Subject: fix uncommon race condition that creates "phantom" servers --- NorthstarDedicatedTest/masterserver.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp index b08ebb90..b5f87274 100644 --- a/NorthstarDedicatedTest/masterserver.cpp +++ b/NorthstarDedicatedTest/masterserver.cpp @@ -897,6 +897,10 @@ void MasterServerManager::AddSelfToServerList( { Sleep(5000); + // defensive check, as m_ownServer could be set to null during the Sleep(5000) above + if (!*m_ownServerId) + return; + do { CURL* curl = curl_easy_init(); @@ -952,6 +956,11 @@ void MasterServerManager::AddSelfToServerList( curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime); CURLcode result = curl_easy_perform(curl); + + // defensive check, as m_ownServerId could be set to null before this request gets processed + if (!*m_ownServerId) + return; + if (result == CURLcode::CURLE_OK) { rapidjson_document serverAddedJson; @@ -1157,6 +1166,7 @@ void MasterServerManager::RemoveSelfFromServerList() curl, CURLOPT_URL, fmt::format("{}/server/remove_server?id={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId).c_str()); + *m_ownServerId = 0; CURLcode result = curl_easy_perform(curl); if (result == CURLcode::CURLE_OK) -- cgit v1.2.3