From 83cffab45f3daf1c423d14ac658b13caa7debab7 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: Sun, 15 Sep 2024 07:37:56 +0000 Subject: [PATCH] Correct cache behavior --- transport/internet/tls/ech.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/transport/internet/tls/ech.go b/transport/internet/tls/ech.go index d013c3d3..177aeb6a 100644 --- a/transport/internet/tls/ech.go +++ b/transport/internet/tls/ech.go @@ -52,18 +52,19 @@ var ( ) func QueryRecord(domain string, server string) (string, error) { - mutex.RLock() - defer mutex.RUnlock() rec, found := dnsCache[domain] if found && rec.expire.After(time.Now()) { - return "", nil + return rec.record, nil } + mutex.Lock() + defer mutex.Unlock() record, err := dohQuery(server, domain) if err != nil { return "", err } rec.record = record rec.expire = time.Now().Add(time.Second * 600) + dnsCache[domain] = rec return record, nil }