Clean query cache before cleaning packet cache. Otherwise the following
situation is possible:
* thread A cleans packet cache
* thread B answers a question for the same name that is being cleaned by A
* since there is no packet cache it populates a packet cache entry from the
query cache (which has not yet been cleaned by thread A
* thread A cleans query cache
* the server will return the old packet cache entry until its TTL expires or
cache is cleaned again
Switching which cache is cleaned first fixes this race condition.
Signed-off-by: Deyan Doychev <deyan@siteground.com>
uint64_t purgeAuthCaches()
{
uint64_t ret = 0;
- ret += PC.purge();
+ /* Clean query cache before packet cache to avoid potential race condition */
ret += QC.purge();
+ ret += PC.purge();
return ret;
}
uint64_t purgeAuthCaches(const std::string& match)
{
uint64_t ret = 0;
- ret += PC.purge(match);
+ /* Clean query cache before packet cache to avoid potential race condition */
ret += QC.purge(match);
+ ret += PC.purge(match);
return ret;
}
uint64_t purgeAuthCachesExact(const DNSName& qname)
{
uint64_t ret = 0;
- ret += PC.purgeExact(qname);
+ /* Clean query cache before packet cache to avoid potential race condition */
ret += QC.purgeExact(qname);
+ ret += PC.purgeExact(qname);
return ret;
}