Skip to content

Commit

Permalink
fix: better protect DNSCache.Set
Browse files Browse the repository at this point in the history
  • Loading branch information
ohaiibuzzle committed Aug 16, 2024
1 parent 344dffc commit 03df2dd
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions dns/dns_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 03df2dd

Please sign in to comment.