Skip to content

Commit

Permalink
resolver: for no-answer cached entries, prefer orig ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
ignoramous committed Sep 1, 2023
1 parent eb7cc95 commit a5b5ebb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/plugins/dns-op/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,11 +459,13 @@ DNSResolver.prototype.resolveDnsFromCache = async function (rxid, packet) {
if (!k) throw new Error("resolver: no cache-key");

const cr = await this.cache.get(k);
const hasAns = cr && dnsutil.isAnswer(cr.dnsPacket);
const freshAns = hasAns && cacheutil.isAnswerFresh(cr.metadata);
this.log.d(rxid, "cache ans", k.href, "ans?", hasAns, "fresh?", freshAns);
const isAns = cr && dnsutil.isAnswer(cr.dnsPacket);
const hasAns = isAns && dnsutil.hasAnswers(cr.dnsPacket);
// if cr has answers, use probablistic expiry; otherwise prefer actual ttl
const fresh = isAns && cacheutil.isAnswerFresh(cr.metadata, hasAns ? 0 : 6);
this.log.d(rxid, "cache ans", k.href, "ans?", isAns, "fresh?", fresh);

if (!hasAns || !freshAns) {
if (!isAns || !fresh) {
return Promise.reject(new Error("resolver: cache miss"));
}

Expand Down

0 comments on commit a5b5ebb

Please sign in to comment.