Merge pull request #8112 from heinrich5991/pr_ddnet_http_age_crash

Fix crash when the serverlist request fails
This commit is contained in:
Robert Müller 2024-03-16 22:40:48 +00:00 committed by GitHub
commit acfe26e715
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -400,21 +400,24 @@ void CServerBrowserHttp::Update()
Success = Success && pJson; Success = Success && pJson;
Success = Success && !Parse(pJson, &m_vServers, &m_vLegacyServers); Success = Success && !Parse(pJson, &m_vServers, &m_vLegacyServers);
json_value_free(pJson); json_value_free(pJson);
int Age = SanitizeAge(pGetServers->ResultAgeSeconds());
if(!Success) if(!Success)
{ {
log_error("serverbrowser_http", "failed getting serverlist, trying to find best URL"); log_error("serverbrowser_http", "failed getting serverlist, trying to find best URL");
m_pChooseMaster->Reset(); m_pChooseMaster->Reset();
m_pChooseMaster->Refresh(); m_pChooseMaster->Refresh();
} }
// Try to find new master if the current one returns results else
// that are 5 minutes old. {
else if(Age > 300) // Try to find new master if the current one returns
// results that are 5 minutes old.
int Age = SanitizeAge(pGetServers->ResultAgeSeconds());
if(Age > 300)
{ {
log_info("serverbrowser_http", "got stale serverlist, age=%ds, trying to find best URL", Age); log_info("serverbrowser_http", "got stale serverlist, age=%ds, trying to find best URL", Age);
m_pChooseMaster->Refresh(); m_pChooseMaster->Refresh();
} }
} }
}
} }
void CServerBrowserHttp::Refresh() void CServerBrowserHttp::Refresh()
{ {