dns_cache: fix cache timeout issue

This commit is contained in:
Nick Peng
2023-09-27 23:19:45 +08:00
parent 51c81513ab
commit 3916ea570a
2 changed files with 33 additions and 18 deletions

View File

@@ -257,7 +257,7 @@ static void dns_cache_expired(struct tw_timer_list *timer, void *data, unsigned
}
dns_cache->del_pending = 1;
dns_timer_mod(&dns_cache->timer, 3);
dns_timer_mod(&dns_cache->timer, 5);
}
static int _dns_cache_replace(struct dns_cache_key *cache_key, int ttl, int speed, int timeout, int update_time,
@@ -283,7 +283,6 @@ static int _dns_cache_replace(struct dns_cache_key *cache_key, int ttl, int spee
/* update cache data */
pthread_mutex_lock(&dns_cache_head.lock);
dns_cache->del_pending = 0;
dns_cache->info.ttl = ttl;
dns_cache->info.qtype = cache_key->qtype;
dns_cache->info.query_flag = cache_key->query_flag;
dns_cache->info.ttl = ttl;
@@ -614,6 +613,10 @@ static int _dns_cache_read_to_cache(struct dns_cache_record *cache_record, struc
if (timeout < DNS_CACHE_READ_TIMEOUT * 2) {
timeout = DNS_CACHE_READ_TIMEOUT + (rand_r(&seed_tmp) % DNS_CACHE_READ_TIMEOUT);
}
if (timeout > dns_conf_serve_expired_ttl && dns_conf_serve_expired_ttl >= 0) {
timeout = dns_conf_serve_expired_ttl;
}
info->timeout = timeout;
if (_dns_cache_insert(&cache_record->info, cache_data, head) != 0) {