Socket
Socket
Sign inDemoInstall

cacheable-lookup

Package Overview
Dependencies
0
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.2 to 5.0.3

2

package.json
{
"name": "cacheable-lookup",
"version": "5.0.2",
"version": "5.0.3",
"description": "A cacheable dns.lookup(…) that respects the TTL",

@@ -5,0 +5,0 @@ "engines": {

@@ -274,4 +274,3 @@ 'use strict';

],
cacheTtl,
isLookup: false
cacheTtl
};

@@ -281,12 +280,2 @@ }

async _lookup(hostname) {
const empty = {
entries: [],
cacheTtl: 0,
isLookup: true
};
if (!this._fallback) {
return empty;
}
try {

@@ -299,7 +288,9 @@ const entries = await this._dnsLookup(hostname, {

entries,
cacheTtl: 0,
isLookup: true
cacheTtl: 0
};
} catch (_) {
return empty;
return {
entries: [],
cacheTtl: 0
};
}

@@ -335,20 +326,20 @@ }

const resolverPromise = this._resolve(hostname);
const lookupPromise = this._lookup(hostname);
try {
let query = await this._resolve(hostname);
let query;
if (query.entries.length === 0 && this._fallback) {
query = await this._lookup(hostname);
try {
query = await Promise.race([
resolverPromise,
lookupPromise
]);
if (query.entries.length === 0) {
if (query.isLookup) {
query = await resolverPromise;
} else {
query = await lookupPromise;
if (query.entries.length !== 0) {
// Use `dns.lookup(...)` for that particular hostname
this._hostnamesToFallback.add(hostname);
}
}
const cacheTtl = query.entries.length === 0 ? this.errorTtl : query.cacheTtl;
await this._set(hostname, query.entries, cacheTtl);
delete this._pending[hostname];
return query.entries;
} catch (error) {

@@ -359,26 +350,2 @@ delete this._pending[hostname];

}
(async () => {
if (query.isLookup) {
try {
const realDnsQuery = await resolverPromise;
// If no DNS entries found
if (realDnsQuery.entries.length === 0) {
// Use `dns.lookup(...)` for that particular hostname
this._hostnamesToFallback.add(hostname);
} else {
await this._set(hostname, realDnsQuery.entries, realDnsQuery.cacheTtl);
}
} catch (_) {}
} else {
const cacheTtl = query.entries.length === 0 ? this.errorTtl : query.cacheTtl;
await this._set(hostname, query.entries, cacheTtl);
}
delete this._pending[hostname];
})();
return query.entries;
}

@@ -385,0 +352,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc