fix: potential overwriting deadline of DNS upstream resolution

This commit is contained in:
mzz2017 2023-03-24 02:35:09 +08:00
parent c2e02482d0
commit a3bf4e1ebd
2 changed files with 11 additions and 2 deletions

View File

@ -226,9 +226,12 @@ func (c *DnsController) UpdateDnsCache(host string, dnsTyp string, answers []dns
c.dnsCacheMu.Lock()
cache, ok := c.dnsCache[cacheKey]
if ok {
c.dnsCacheMu.Unlock()
cache.Deadline = deadline
// To avoid overwriting DNS upstream resolution.
if deadline.After(cache.Deadline) {
cache.Deadline = deadline
}
cache.Answers = answers
c.dnsCacheMu.Unlock()
} else {
cache, err = c.newCache(fqdn, answers, deadline)
if err != nil {

View File

@ -204,6 +204,12 @@ func (c *ControlPlane) handlePkt(lConn *net.UDPConn, data []byte, src, pktDst, r
retry := 0
getNew:
if retry > MaxRetry {
c.log.WithFields(logrus.Fields{
"src": RefineSourceToShow(realSrc, realDst.Addr(), lanWanFlag),
"network": networkType.String(),
"dialer": ue.Dialer.Property().Name,
"retry": retry,
}).Warnln("Touch max retry limit.")
return fmt.Errorf("touch max retry limit")
}
ue, isNew, err := DefaultUdpEndpointPool.GetOrCreate(realSrc, &UdpEndpointOptions{