Skip to content

Commit

Permalink
proxy: fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Dec 2, 2022
1 parent 7aa32db commit 881fbc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions proxy/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,19 @@ func (c *cache) clearItems() {
c.itemsLock.Lock()
defer c.itemsLock.Unlock()

c.items.Clear()
if c.items != nil {
c.items.Clear()
}
}

// clearItemsWithSubnet empties the subnet cache.
func (c *cache) clearItemsWithSubnet() {
c.itemsWithSubnetLock.Lock()
defer c.itemsWithSubnetLock.Unlock()

c.itemsWithSubnet.Clear()
if c.itemsWithSubnet != nil {
c.itemsWithSubnet.Clear()
}
}

// cacheTTL returns the number of seconds for which m is valid to be cached.
Expand Down
2 changes: 1 addition & 1 deletion proxy/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ func TestCache_expired(t *testing.T) {
key := msgToKey(reply)
data := (&cacheItem{
m: reply,
ttl: tc.ttl,
u: testUpsAddr,
ttl: tc.ttl,
}).pack()
testCache.items.Set(key, data)
t.Cleanup(testCache.items.Clear)
Expand Down

0 comments on commit 881fbc0

Please sign in to comment.