@@ -85,7 +85,11 @@ const RECV_BUFFER = true;
8585const SEND_BUFFER = false ;
8686
8787// Lazily loaded
88- let cluster = null ;
88+ let _cluster = null ;
89+ function lazyLoadCluster ( ) {
90+ if ( ! _cluster ) _cluster = require ( 'cluster' ) ;
91+ return _cluster ;
92+ }
8993
9094const errnoException = errors . errnoException ;
9195const exceptionWithHostPort = errors . exceptionWithHostPort ;
@@ -200,8 +204,7 @@ function bufferSize(self, size, buffer) {
200204
201205// Query primary process to get the server handle and utilize it.
202206function bindServerHandle ( self , options , errCb ) {
203- if ( ! cluster )
204- cluster = require ( 'cluster' ) ;
207+ const cluster = lazyLoadCluster ( ) ;
205208
206209 const state = self [ kStateSymbol ] ;
207210 cluster . _getServer ( self , options , ( err , handle ) => {
@@ -262,8 +265,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
262265 const exclusive = ! ! port . exclusive ;
263266 const state = this [ kStateSymbol ] ;
264267
265- if ( ! cluster )
266- cluster = require ( 'cluster' ) ;
268+ const cluster = lazyLoadCluster ( ) ;
267269
268270 if ( cluster . isWorker && ! exclusive ) {
269271 bindServerHandle ( this , {
@@ -325,8 +327,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) {
325327 return ;
326328 }
327329
328- if ( ! cluster )
329- cluster = require ( 'cluster' ) ;
330+ const cluster = lazyLoadCluster ( ) ;
330331
331332 let flags = 0 ;
332333 if ( state . reuseAddr )
0 commit comments