coredns/plugin/pkg/cache
Charlie Vieth 031dfede90 pkg/cache: fix race in Add() and Evict() (#3013)
* pkg/cache: fix race in Add() and Evict()

This fixes a race in Add() when the shard is at max capacity and the key
being added is already stored.  Previously, the shard would evict a
random value - when all it needed to do was replace an existing value.
There was a race in how Evict() picked which key to remove, which would
cause concurrent calls to Evict() to remove the same key.

Additionally, this commit removes a lot of the lock contention and a
race around Add() and Evict() by changing them to immediately hold the
write lock.  Previously, they would check conditions with the read lock
held and not re-check those conditions once the write lock was acquired
(this is a race).

* pkg/cache: code review comments

* pkg/cache: simplify Add() logic
2019-07-19 09:19:03 +00:00
..
cache.go pkg/cache: fix race in Add() and Evict() (#3013) 2019-07-19 09:19:03 +00:00
cache_test.go pkg/cache: fix race in Add() and Evict() (#3013) 2019-07-19 09:19:03 +00:00
shard_test.go pkg/cache: fix race in Add() and Evict() (#3013) 2019-07-19 09:19:03 +00:00