Skip to content

Commit eac7aad

Browse 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

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎lib/net.js‎

Lines 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-
constdns=require('dns');
7978

8079
constkLastWriteQueueSize=Symbol('lastWriteQueueSize');
8180

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

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

1036+
1037+
if(dns===undefined)dns=require('dns');
10371038
vardnsopts={
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
functionlookupAndListen(self,port,address,backlog,exclusive){
1486+
if(dns===undefined)dns=require('dns');
14851487
dns.lookup(address,functiondoListen(err,ip,addressType){
14861488
if(err){
14871489
self.emit('error',err);

0 commit comments

Comments
 (0)