@@ -138,6 +138,8 @@ struct dns_cache_entry
138138static struct dns_cache_entry * dns_cache = NULL ;
139139/* 5 min timeout, in usec */
140140static const retro_time_t dns_cache_timeout = 1000 /* usec/ms */ * 1000 /* ms/s */ * 60 /* s/min */ * 5 /* min */ ;
141+ /* only cache failures for 30 seconds */
142+ static const retro_time_t dns_cache_fail_timeout = 1000 /* usec/ms */ * 1000 /* ms/s */ * 30 /* s */ ;
141143#ifdef HAVE_THREADS
142144static slock_t * dns_cache_lock = NULL ;
143145#endif
@@ -690,13 +692,15 @@ static void net_http_dns_cache_remove_expired(void)
690692 struct dns_cache_entry * prev = NULL ;
691693 while (entry )
692694 {
693- if (entry -> timestamp + dns_cache_timeout < cpu_features_get_time_usec ())
695+ if ( (entry -> addr && (entry -> timestamp + dns_cache_timeout < cpu_features_get_time_usec ()))
696+ || (!entry -> addr && (entry -> timestamp + dns_cache_fail_timeout < cpu_features_get_time_usec ())))
694697 {
695698 if (prev )
696699 prev -> next = entry -> next ;
697700 else
698701 dns_cache = entry -> next ;
699- freeaddrinfo_retro (entry -> addr );
702+ if (entry -> addr )
703+ freeaddrinfo_retro (entry -> addr );
700704 free (entry -> domain );
701705 free (entry );
702706 entry = prev ? prev -> next : dns_cache ;
@@ -720,7 +724,9 @@ static struct dns_cache_entry *net_http_dns_cache_find(const char *domain, int p
720724 {
721725 if (port == entry -> port && string_is_equal (entry -> domain , domain ))
722726 {
723- entry -> timestamp = cpu_features_get_time_usec ();
727+ /* don't bump timeestamp for failures */
728+ if (entry -> addr )
729+ entry -> timestamp = cpu_features_get_time_usec ();
724730 return entry ;
725731 }
726732 entry = entry -> next ;
0 commit comments