diff --git a/lib/net.js b/lib/net.js index 65d57b2b89545b..0b8284fbdea1b8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -836,26 +836,20 @@ function internalConnect( var err; if (localAddress || localPort) { - var bind; + debug('binding to localAddress: %s and localPort: %d (addressType: %d)', + localAddress, localPort, addressType); if (addressType === 4) { localAddress = localAddress || '0.0.0.0'; - bind = self._handle.bind; + err = self._handle.bind(localAddress, localPort); } else if (addressType === 6) { localAddress = localAddress || '::'; - bind = self._handle.bind6; + err = self._handle.bind6(localAddress, localPort); } else { self._destroy(new TypeError('Invalid addressType: ' + addressType)); return; } - debug('binding to localAddress: %s and localPort: %d', - localAddress, - localPort); - - bind = bind.bind(self._handle); - err = bind(localAddress, localPort); - if (err) { const ex = exceptionWithHostPort(err, 'bind', localAddress, localPort); self._destroy(ex);