Skip to content

Commit

Permalink
net: lazy load dns
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
BridgeAR authored and MylesBorins committed May 22, 2018
1 parent 328a2c7 commit eac7aad
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@ const {
ERR_SOCKET_BAD_PORT,
ERR_SOCKET_CLOSED
} = errors.codes;
const dns = require('dns');

const kLastWriteQueueSize = Symbol('lastWriteQueueSize');

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

const errnoException = errors.errnoException;
const exceptionWithHostPort = errors.exceptionWithHostPort;
Expand Down Expand Up @@ -1034,6 +1033,8 @@ function lookupAndConnect(self, options) {
throw new ERR_INVALID_ARG_TYPE('options.lookup',
'Function', options.lookup);


if (dns === undefined) dns = require('dns');
var dnsopts = {
family: options.family,
hints: options.hints || 0
Expand Down Expand Up @@ -1368,7 +1369,7 @@ function listenInCluster(server, address, port, addressType,
backlog, fd, exclusive) {
exclusive = !!exclusive;

if (cluster === null) cluster = require('cluster');
if (cluster === undefined) cluster = require('cluster');

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

function lookupAndListen(self, port, address, backlog, exclusive) {
if (dns === undefined) dns = require('dns');
dns.lookup(address, function doListen(err, ip, addressType) {
if (err) {
self.emit('error', err);
Expand Down

0 comments on commit eac7aad

Please sign in to comment.