DNS interceptor cache revalidation on request errors #5652
Replies: 2 comments 2 replies
|
Cache entries are cleared up according to their expiration date. Can you build a little lab to reproduce the problem? |
|
I built the lab @mcollina asked for, simulating the Kubernetes case: a service whose IP changes while a cached record is still valid. Environment: Node v24.14.1, undici 8.10.0, Result — the failure is real, and the cache is not revalidated on connection errors: So, to answer the question directly: no, this is not handled automatically (as of 8.10.0). Reading
A workaround that works today — the interceptor accepts a custom const records = new Map()
const storage = {
get: (k) => records.get(k) ?? null,
set: (k, v) => records.set(k, v),
delete: (k) => records.delete(k),
full: () => false
}
const dispatcher = new Agent().compose(
interceptors.dns({ maxTTL: 60_000, storage })
)
// on ECONNREFUSED/ETIMEDOUT: storage.delete(host); then retryVerified with the same lab — eviction + retry recovers immediately instead of waiting out the TTL: Two additional mitigations for dynamic environments: keep If there's interest, "evict the specific cached IP on |
Uh oh!
There was an error while loading. Please reload this page.
Hello!
For example, we have a dynamic network environment (Kubernetes), where IP addresses change frequently.
When DNS caching is used and a cached IP address becomes outdated, requests will fail.
Is there a way to clear the DNS cache for these requests after an error occurs? Or is this handled automatically internally?
All reactions