
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
axios-cached-dns-resolve
Advanced tools
Caches dns resolutions made with async dns.resolve instead of default sync dns.lookup, refreshes in background
Axios uses node.js dns.resolve to resolve host names. dns.resolve is synchronous and executes on limited libuv thread pool. Every axios request will resolve the dns name in kubernetes, openshift, and cloud environments that intentionally set TTL low or to 0 for quick dynamic updates. The dns resolvers can be overwhelmed with the load. There is/was a bug in DNS resolver that manifests as very long dns.lookups in node.js.
From the kubernetes documentation
Even if apps and libraries did proper re-resolution, the load of every client re-resolving DNS over and over would be difficult to manage.
This library uses dns.resolve and can optionally cache resolutions and round-robin among addresses. The cache size is configurable. If caching is enabled, a background thread will periodically refresh resolutions with dns.resolve rather than every request. There is an idle TTL that evicts background refresh if an address is no longer being used. This lib proxies through the OS resolution mechanism which may provide further caching.
Node 8+
npm i -S axios-cached-dns-resolve
import { registerInterceptor } from 'axios-cached-dns-resolve'
const axiosClient = axios.create(config)
axiosCachingDns.registerInterceptor(axiosClient)
Use axiosClient as normal
const config = {
dnsTtlMs: process.env.AXIOS_DNS_CACHE_TTL_MS || 5000, // when to refresh actively used dns entries (5 sec)
cacheGraceExpireMultiplier: process.env.AXIOS_DNS_CACHE_EXPIRE_MULTIPLIER || 2, // maximum grace to use entry beyond TTL
dnsIdleTtlMs: process.env.AXIOS_DNS_CACHE_TTL_MS || 1000 * 60 * 10, // when to remove entry entirely if not being used (10 min)
backgroundScanMs: process.env.AXIOS_DNS_BACKGROUND_SCAN_MS || 2400, // how frequently to scan for expired TTL and refresh (2.4 sec)
dnsCacheSize: process.env.AXIOS_DNS_CACHE_SIZE || 100, // maximum number of entries to keep in cache
// pino logging options
logging: {
name: 'kafka-publisher',
// enabled: true,
// level: 'debug', // default 'info' //comment out or set to 'info'
// timestamp: true,
prettyPrint: process.env.NODE_ENV === 'DEBUG' || false,
useLevelLabels: true,
},
}
FAQs
Caches dns resolutions made with async dns.resolve instead of default sync dns.lookup, refreshes in background
The npm package axios-cached-dns-resolve receives a total of 45,329 weekly downloads. As such, axios-cached-dns-resolve popularity was classified as popular.
We found that axios-cached-dns-resolve demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.