From 3bd245f1f7f15e9ef8a99036487a47caabd2fd43 Mon Sep 17 00:00:00 2001 From: Antoine Pultier <45740+fungiboletus@users.noreply.github.com> Date: Thu, 19 Nov 2020 18:43:17 +0100 Subject: [PATCH] Instantiate CacheableLookup only when needed (#1529) --- source/core/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/core/index.ts b/source/core/index.ts index a96d8035a..084d0a3b0 100644 --- a/source/core/index.ts +++ b/source/core/index.ts @@ -31,7 +31,7 @@ import normalizePromiseArguments from '../as-promise/normalize-arguments'; import {PromiseOnly} from '../as-promise/types'; import calculateRetryDelay from './calculate-retry-delay'; -const globalDnsCache = new CacheableLookup(); +let globalDnsCache: CacheableLookup; type HttpRequestFunction = typeof httpRequest; type Error = NodeJS.ErrnoException; @@ -1762,6 +1762,10 @@ export default class Request extends Duplex implements RequestEvents { // `options.dnsCache` if (options.dnsCache === true) { + if (!globalDnsCache) { + globalDnsCache = new CacheableLookup(); + } + options.dnsCache = globalDnsCache; } else if (!is.undefined(options.dnsCache) && !options.dnsCache.lookup) { throw new TypeError(`Parameter \`dnsCache\` must be a CacheableLookup instance or a boolean, got ${is(options.dnsCache)}`);