From 03df2dd3c599bd4e91765336a61b21d6d3b6b831 Mon Sep 17 00:00:00 2001 From: ohaiibuzzle <23693150+ohaiibuzzle@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:28:21 +0700 Subject: [PATCH] fix: better protect DNSCache.Set --- dns/dns_cache.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/dns/dns_cache.go b/dns/dns_cache.go index bdc4a0fe..9c09ec63 100644 --- a/dns/dns_cache.go +++ b/dns/dns_cache.go @@ -33,15 +33,12 @@ func GetCache() *DNSCache { // interface function for the inner map basically. func (d *DNSCache) Set(key string, value string) { - d.cacheLock.RLock() + d.cacheLock.Lock() + defer d.cacheLock.Unlock() if _, ok := d.cacheMap[key]; ok { - d.cacheLock.RUnlock() return } - d.cacheLock.RUnlock() - d.cacheLock.Lock() - defer d.cacheLock.Unlock() d.cacheMap[key] = DNSCacheEntry{ ip: value, expiry_timer: time.AfterFunc(time.Duration(*util.GetConfig().DNSCacheExpiry)*time.Second, func() {