From 1b607ff8742d100bebf7193ff2d64f7fd7eabe89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E6=89=87=E6=BB=91=E7=BF=94=E7=BF=BC?= Date: Thu, 12 Sep 2024 22:34:45 +0800 Subject: [PATCH] DNS: Do not hit cache if encounted err (#3784) --- app/dns/nameserver_doh.go | 2 +- app/dns/nameserver_quic.go | 2 +- app/dns/nameserver_tcp.go | 2 +- app/dns/nameserver_udp.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/dns/nameserver_doh.go b/app/dns/nameserver_doh.go index d34709e9..bc160135 100644 --- a/app/dns/nameserver_doh.go +++ b/app/dns/nameserver_doh.go @@ -365,7 +365,7 @@ func (s *DoHNameServer) QueryIP(ctx context.Context, domain string, clientIP net errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name) } else { ips, err := s.findIPsForDomain(fqdn, option) - if err != errRecordNotFound { + if err == nil || err == dns_feature.ErrEmptyResponse { errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips) log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err}) return ips, err diff --git a/app/dns/nameserver_quic.go b/app/dns/nameserver_quic.go index 2d56f43e..435cd0a3 100644 --- a/app/dns/nameserver_quic.go +++ b/app/dns/nameserver_quic.go @@ -300,7 +300,7 @@ func (s *QUICNameServer) QueryIP(ctx context.Context, domain string, clientIP ne errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name) } else { ips, err := s.findIPsForDomain(fqdn, option) - if err != errRecordNotFound { + if err == nil || err == dns_feature.ErrEmptyResponse { errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips) log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err}) return ips, err diff --git a/app/dns/nameserver_tcp.go b/app/dns/nameserver_tcp.go index bc5bab44..0146e007 100644 --- a/app/dns/nameserver_tcp.go +++ b/app/dns/nameserver_tcp.go @@ -323,7 +323,7 @@ func (s *TCPNameServer) QueryIP(ctx context.Context, domain string, clientIP net errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name) } else { ips, err := s.findIPsForDomain(fqdn, option) - if err != errRecordNotFound { + if err == nil || err == dns_feature.ErrEmptyResponse { errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips) log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err}) return ips, err diff --git a/app/dns/nameserver_udp.go b/app/dns/nameserver_udp.go index 24a99593..47d70435 100644 --- a/app/dns/nameserver_udp.go +++ b/app/dns/nameserver_udp.go @@ -250,7 +250,7 @@ func (s *ClassicNameServer) QueryIP(ctx context.Context, domain string, clientIP errors.LogDebug(ctx, "DNS cache is disabled. Querying IP for ", domain, " at ", s.name) } else { ips, err := s.findIPsForDomain(fqdn, option) - if err != errRecordNotFound { + if err == nil || err == dns_feature.ErrEmptyResponse { errors.LogDebugInner(ctx, err, s.name, " cache HIT ", domain, " -> ", ips) log.Record(&log.DNSLog{Server: s.name, Domain: domain, Result: ips, Status: log.DNSCacheHit, Elapsed: 0, Error: err}) return ips, err