@@ -75,13 +75,12 @@ const {
7575 ERR_SOCKET_BAD_PORT ,
7676 ERR_SOCKET_CLOSED
7777} = errors . codes ;
78- const dns = require ( 'dns' ) ;
7978
8079const 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
8685const errnoException = errors . errnoException ;
8786const 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
14841485function 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