From 5586c3c10b46c9b8bfda6a04ba125d1966fdc279 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Thu, 6 May 2021 14:41:55 +0800 Subject: [PATCH] dgram: refactor to remove unreachable code There is no need to ensure `cluster` loaded in `bindServerHandle` because it's already loaded before calling it. This PR makes `cluster` as an argument to remind developers that `cluster` needs to be loaded before calling this function. --- lib/dgram.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/dgram.js b/lib/dgram.js index c59fdf8a4af11e..01bed97025ebf4 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -199,10 +199,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'); - +function bindServerHandle(cluster, self, options, errCb) { const state = self[kStateSymbol]; cluster._getServer(self, options, (err, handle) => { if (err) { @@ -266,7 +263,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { cluster = require('cluster'); if (cluster.isWorker && !exclusive) { - bindServerHandle(this, { + bindServerHandle(cluster, this, { address: null, port: null, addressType: this.type, @@ -335,7 +332,7 @@ Socket.prototype.bind = function(port_, address_ /* , callback */) { flags |= UV_UDP_IPV6ONLY; if (cluster.isWorker && !exclusive) { - bindServerHandle(this, { + bindServerHandle(cluster, this, { address: ip, port: port, addressType: this.type,