DNS: Avoid mutating cache records during cleanup (#7442)

https://github.com/XTLS/Xray-core/pull/7442#pullrequestreview-5958707394

---------

Co-authored-by: Meow <197331664+Meo597@users.noreply.github.com>
This commit is contained in:
TurboRigby
2026-11-19 12:36:34 +00:00
committed by GitHub
co-authored by Meow
parent 09b1b0701f
commit febc082f03
+8 -5
View File
@@ -124,14 +124,17 @@ func (c *CacheController) writeAndShrink(expiredKeys []string) {
if rec == nil {
continue
}
if rec.A != nil && rec.A.Expire.Before(now) {
rec.A = nil
a, aaaa := rec.A, rec.AAAA
if a != nil && a.Expire.Before(now) {
a = nil
}
if rec.AAAA != nil && rec.AAAA.Expire.Before(now) {
rec.AAAA = nil
if aaaa != nil && aaaa.Expire.Before(now) {
aaaa = nil
}
if rec.A == nil && rec.AAAA == nil {
if a == nil && aaaa == nil {
delete(c.ips, domain)
} else if a != rec.A || aaaa != rec.AAAA {
c.ips[domain] = &record{A: a, AAAA: aaaa}
}
}