diff --git a/lib/dgram.js b/lib/dgram.js index c59fdf8a4af11e..79ed314295b08f 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -86,6 +86,9 @@ const SEND_BUFFER = false; // Lazily loaded let cluster = null; +function lazyLoadCluster() { + if (!cluster) cluster = require('cluster'); +} const errnoException = errors.errnoException; const exceptionWithHostPort = errors.exceptionWithHostPort; @@ -200,8 +203,7 @@ function bufferSize(self, size, buffer) { // Query primary process to get the server handle and utilize it. function bindServerHandle(self, options, errCb) { - if (!cluster) - cluster = require('cluster'); + lazyLoadCluster(); const state = self[kStateSymbol]; cluster._getServer(self, options, (err, handle) => { @@ -262,8 +264,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { const exclusive = !!port.exclusive; const state = this[kStateSymbol]; - if (!cluster) - cluster = require('cluster'); + lazyLoadCluster(); if (cluster.isWorker && !exclusive) { bindServerHandle(this, { @@ -325,8 +326,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { return; } - if (!cluster) - cluster = require('cluster'); + lazyLoadCluster(); let flags = 0; if (state.reuseAddr)