dns: lazy loaded

PR-URL: https://github.com/nodejs/node/pull/20567
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Ruben Bridgewater authored and Myles Borins committed 2018-05-22 14:13:28 -04:00
1 parent 28d00a18c8
commit 60eab9100f
1 file changed
+6 -3
+6 -3
View File
@@ -35,7 +35,6 @@ const {
ERR_SOCKET_DGRAM_NOT_RUNNING
} = errors.codes;
const { Buffer } = require('buffer');
const dns = require('dns');
const util = require('util');
const { isUint8Array } = require('internal/util/types');
const EventEmitter = require('events');
@@ -47,6 +46,9 @@ const { UV_UDP_REUSEADDR } = process.binding('constants').os;
const { UDP, SendWrap } = process.binding('udp_wrap');
// Lazy load for startup performance.
let dns;
const BIND_STATE_UNBOUND = 0;
const BIND_STATE_BINDING = 1;
const BIND_STATE_BOUND = 2;
@@ -72,9 +74,10 @@ function lookup6(lookup, address, callback) {
function newHandle(type, lookup) {
if (lookup === undefined)
if (lookup === undefined) {
if (dns === undefined) dns = require('dns');
lookup = dns.lookup;
else if (typeof lookup !== 'function')
} else if (typeof lookup !== 'function')
throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup);
if (type === 'udp4') {