Bug 208312. Cache DNS failure responses, not just successful lookups. r+sr=bzbarsky

This commit is contained in:
Patrick McManus 2008-10-13 17:04:09 -04:00
parent 055d1e76f5
commit 26fb25117e
2 changed files with 22 additions and 3 deletions

View File

@ -186,6 +186,7 @@ nsHostRecord::Create(const nsHostKey *key, nsHostRecord **result)
rec->resolving = PR_FALSE;
PR_INIT_CLIST(rec);
PR_INIT_CLIST(&rec->callbacks);
rec->negative = PR_FALSE;
memcpy((char *) rec->host, key->host, hostLen);
*result = rec;
@ -456,6 +457,13 @@ nsHostResolver::ResolveHost(const char *host,
LOG(("using cached record\n"));
// put reference to host record on stack...
result = he->rec;
if (he->rec->negative) {
status = NS_ERROR_UNKNOWN_HOST;
if (!he->rec->resolving)
// return the cached failure to the caller, but try and refresh
// the record in the background
IssueLookup(he->rec);
}
}
// if the host name is an IP address literal and has been parsed,
// go ahead and use it.
@ -638,8 +646,14 @@ nsHostResolver::OnLookupComplete(nsHostRecord *rec, nsresult status, PRAddrInfo
if (old_addr_info)
PR_FreeAddrInfo(old_addr_info);
rec->expiration = NowInMinutes();
if (result)
if (result) {
rec->expiration += mMaxCacheLifetime;
rec->negative = PR_FALSE;
}
else {
rec->expiration += 1; /* one minute for negative cache */
rec->negative = PR_TRUE;
}
rec->resolving = PR_FALSE;
if (rec->addr_info && !mShutdown) {

View File

@ -104,12 +104,17 @@ public:
* thread doesn't need to lock when reading |addr_info|.
*/
PRLock *addr_info_lock;
PRAddrInfo *addr_info;
int addr_info_gencnt; /* generation count of |addr_info| */
PRAddrInfo *addr_info;
PRNetAddr *addr;
PRBool negative; /* True if this record is a cache of a failed lookup.
Negative cache entries are valid just like any other
(though never for more than 60 seconds), but a use
of that negative entry forces an asynchronous refresh. */
PRUint32 expiration; /* measured in minutes since epoch */
PRBool HasResult() const { return addr_info || addr; }
PRBool HasResult() const { return addr_info || addr || negative; }
private:
friend class nsHostResolver;