From febc082f039e8d14bf57a934f8cb206cbc3ade6a Mon Sep 17 00:00:00 2001 From: TurboRigby <100000848+TurboRigby@users.noreply.github.com> Date: Thu, 19 Nov 2026 14:36:34 +0200 Subject: [PATCH] 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> --- app/dns/cache_controller.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/dns/cache_controller.go b/app/dns/cache_controller.go index 6e2fd6c97..f3f6b1b67 100644 --- a/app/dns/cache_controller.go +++ b/app/dns/cache_controller.go @@ -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} } }