net_http: expire dns lookup failures more quickly (#17481)

This commit is contained in:
Eric Warmenhoven 2025-01-28 17:27:51 -05:00 committed by GitHub
parent d00ee5a70b
commit 12f66bebb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 3 deletions

View File

@ -138,6 +138,8 @@ struct dns_cache_entry
static struct dns_cache_entry *dns_cache = NULL;
/* 5 min timeout, in usec */
static const retro_time_t dns_cache_timeout = 1000 /* usec/ms */ * 1000 /* ms/s */ * 60 /* s/min */ * 5 /* min */;
/* only cache failures for 30 seconds */
static const retro_time_t dns_cache_fail_timeout = 1000 /* usec/ms */ * 1000 /* ms/s */ * 30 /* s */;
#ifdef HAVE_THREADS
static slock_t *dns_cache_lock = NULL;
#endif
@ -690,12 +692,14 @@ static void net_http_dns_cache_remove_expired(void)
struct dns_cache_entry *prev = NULL;
while (entry)
{
if (entry->timestamp + dns_cache_timeout < cpu_features_get_time_usec())
if ( (entry->addr && (entry->timestamp + dns_cache_timeout < cpu_features_get_time_usec()))
|| (!entry->addr && (entry->timestamp + dns_cache_fail_timeout < cpu_features_get_time_usec())))
{
if (prev)
prev->next = entry->next;
else
dns_cache = entry->next;
if (entry->addr)
freeaddrinfo_retro(entry->addr);
free(entry->domain);
free(entry);
@ -720,6 +724,8 @@ static struct dns_cache_entry *net_http_dns_cache_find(const char *domain, int p
{
if (port == entry->port && string_is_equal(entry->domain, domain))
{
/* don't bump timeestamp for failures */
if (entry->addr)
entry->timestamp = cpu_features_get_time_usec();
return entry;
}