dnsResolve called repeatedly for the same host
low
Repeated dnsResolve(host) calls for one name are usually answered from a cache, but Windows (WinHTTP) waits again on every call when DNS does not answer, pactester asks for every call, and in Chrome dnsResolve plus dnsResolveEx for one name are two lookups. Resolve once into a local variable.
Why it matters
JavaScript does not remember the result of a function call, but the engines’ DNS caches do.
In Chrome, Edge, Firefox and Windows a repeated dnsResolve(host) for a name that resolves is
answered from a cache: in the lab on 2026-10-14, 150 calls for one name in one run sent one
DNS query in each of them. Three isInNet(dnsResolve(host), ...) calls for three ranges are therefore not three
queries there.
Resolving once is still the right way to write it, for three reasons:
- Windows (WinHTTP) keeps no table of names during one run. When the DNS server does not answer, for example on a laptop outside the company network, every call waits for the timeout again, about 12 seconds on Windows 11: 10 calls made one request wait 120 seconds.
- pactester (pacparser) and other engines without a cache send a query to the DNS server for every call unless the system they run on caches answers.
- Chrome and Edge store
dnsResolveanddnsResolveExfor the same name as separate entries, so a script that mixes them asks twice, and both count towards the limit of 20 different names per request.
Keep the variable local to FindProxyForURL; a cache in a top-level variable is a different
problem (PAC-K008). Resolving once reduces the cost but keeps the dependency on DNS; see
PAC-P001 for removing it.
How to fix
var ip = dnsResolve(host); inside FindProxyForURL, then use ip in every isInNet call and test a failed lookup with if (!ip), because Windows returns false instead of null.
Examples
Bad
function FindProxyForURL(url, host) {
if (isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") ||
isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0") ||
isInNet(dnsResolve(host), "192.168.0.0", "255.255.0.0")) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open bad example in checkerGood
function FindProxyForURL(url, host) {
if (isPlainHostName(host) || dnsDomainIs(host, ".corp.example")) {
return "DIRECT";
}
var ip = dnsResolve(host);
if (ip && (isInNet(ip, "10.0.0.0", "255.0.0.0") ||
isInNet(ip, "172.16.0.0", "255.240.0.0") ||
isInNet(ip, "192.168.0.0", "255.255.0.0"))) {
return "DIRECT";
}
return "PROXY proxy.corp.example:8080";
}
Open good example in checkerEngine behaviour
| Engine | Behaviour | Source |
|---|---|---|
| chromium | Keeps the answers of one request in a table, failures included, so a repeat of dnsResolve(host) costs no lookup. dnsResolve and dnsResolveEx for the same name are separate entries. Limit of 20 different names per request. | code, verified 2026-10-14 · ref |
| firefox | No table in the PAC engine; every call asks the browser's DNS cache, which answers repeats and keeps a failure for 60 s. 150 calls for one name sent one query in the lab. | lab, verified 2026-10-14 · ref |
| pacparser | No cache: every call asks the system's resolver again. 150 calls for one name sent 150 queries on a system without a caching DNS service. | lab, verified 2026-10-14 · ref |
| winhttp | Repeats for a name that resolves are answered from the Windows DNS cache (150 calls, one query). When the DNS server does not answer, every call waits about 12 s again, also inside one run (Windows 11, lab). | lab, verified 2026-10-14 |
The PAC functions this rule is about
dnsResolve(): Resolves a host name to an IP address string, or null when the name does not resolve (false in Windows). The script waits for the answer; repeats for the same name come from a cache.dnsResolveEx(): Microsoft IPv6 extension. Returns a semicolon-separated list of IPv4 and IPv6 addresses, or an empty string (false in Windows).
Related rules
- DNS function on the path of every request PAC-P001
- isInNet called with a hostname PAC-P002
- Mutable state outside FindProxyForURL PAC-K008