util/lru: update c.head when deleting the most recently used entry

Fixes tailscale/corp#14747

Signed-off-by: David Anderson <danderson@tailscale.com>
Co-authored-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2023-09-19 10:46:25 -07:00
committed by Dave Anderson
parent 4232826cce
commit ed50f360db
2 changed files with 154 additions and 0 deletions

View File

@ -174,6 +174,9 @@ func (c *Cache[K, V]) deleteElement(ent *entry[K, V]) {
} else {
ent.next.prev = ent.prev
ent.prev.next = ent.next
if c.head == ent {
c.head = ent.next
}
}
delete(c.lookup, ent.key)
}