Skip to content

Commit eac7aad

Browse files
BridgeARMylesBorins
authored andcommitted
net: lazy load dns
PR-URL: #20567 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 328a2c7 commit eac7aad

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/net.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ const {
7575
ERR_SOCKET_BAD_PORT,
7676
ERR_SOCKET_CLOSED
7777
} = errors.codes;
78-
const dns = require('dns');
7978

8079
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
8180

82-
// `cluster` is only used by `listenInCluster` so for startup performance
83-
// reasons it's lazy loaded.
84-
var cluster = null;
81+
// Lazy loaded to improve startup performance.
82+
let cluster;
83+
let dns;
8584

8685
const errnoException = errors.errnoException;
8786
const exceptionWithHostPort = errors.exceptionWithHostPort;
@@ -1034,6 +1033,8 @@ function lookupAndConnect(self, options) {
10341033
throw new ERR_INVALID_ARG_TYPE('options.lookup',
10351034
'Function', options.lookup);
10361035

1036+
1037+
if (dns === undefined) dns = require('dns');
10371038
var dnsopts = {
10381039
family: options.family,
10391040
hints: options.hints || 0
@@ -1368,7 +1369,7 @@ function listenInCluster(server, address, port, addressType,
13681369
backlog, fd, exclusive) {
13691370
exclusive = !!exclusive;
13701371

1371-
if (cluster === null) cluster = require('cluster');
1372+
if (cluster === undefined) cluster = require('cluster');
13721373

13731374
if (cluster.isMaster || exclusive) {
13741375
// Will create a new handle
@@ -1482,6 +1483,7 @@ Server.prototype.listen = function(...args) {
14821483
};
14831484

14841485
function lookupAndListen(self, port, address, backlog, exclusive) {
1486+
if (dns === undefined) dns = require('dns');
14851487
dns.lookup(address, function doListen(err, ip, addressType) {
14861488
if (err) {
14871489
self.emit('error', err);

0 commit comments

Comments
 (0)