From 89e958abfaba227204aa96aface8762c398ef2d6 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Fri, 14 Jul 2023 20:44:10 +0800 Subject: [PATCH] dns_client: avoid false re-creation of udp sockets causing retries. --- src/dns_client.c | 7 ++++++- src/smartdns.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dns_client.c b/src/dns_client.c index 4756a67..ea4dcc2 100644 --- a/src/dns_client.c +++ b/src/dns_client.c @@ -4131,7 +4131,12 @@ static void _dns_client_period_run(unsigned int msec) { /* free timed out query, and notify caller */ list_del_init(&query->period_list); - _dns_client_check_udp_nat(query); + + /* check udp nat after retrying. */ + if (atomic_read(&query->retry_count) == 1) { + _dns_client_check_udp_nat(query); + } + if (atomic_dec_and_test(&query->retry_count) || (query->has_result != 0)) { _dns_client_query_remove(query); if (query->has_result == 0) { diff --git a/src/smartdns.c b/src/smartdns.c index 3c986f2..730ca81 100644 --- a/src/smartdns.c +++ b/src/smartdns.c @@ -460,8 +460,13 @@ static int _smartdns_init(void) const char *logfile = _smartdns_log_path(); int i = 0; char logdir[PATH_MAX] = {0}; + int logbuffersize = 0; - ret = tlog_init(logfile, dns_conf_log_size, dns_conf_log_num, 0, 0); + if (get_system_mem_size() > 1024 * 1024 * 1024) { + logbuffersize = 1024 * 1024; + } + + ret = tlog_init(logfile, dns_conf_log_size, dns_conf_log_num, logbuffersize, TLOG_NONBLOCK); if (ret != 0) { tlog(TLOG_ERROR, "start tlog failed.\n"); goto errout;