Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit eac7aad

Browse filesBrowse files
BridgeARMylesBorins
authored andcommitted
net: lazy load dns
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>
1 parent 328a2c7 commit eac7aad
Copy full SHA for eac7aad

File tree

Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-5
lines changed
Open diff view settings
Collapse file

‎lib/net.js‎

Copy file name to clipboardExpand all lines: lib/net.js
+7-5Lines changed: 7 additions & 5 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.