mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
net: lazy load dns
PR-URL: https://github.com/nodejs/node/pull/20567 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
bf46c371eb
commit
c07e85123e
12
lib/net.js
12
lib/net.js
@ -75,13 +75,12 @@ const {
|
||||
ERR_SOCKET_BAD_PORT,
|
||||
ERR_SOCKET_CLOSED
|
||||
} = errors.codes;
|
||||
const dns = require('dns');
|
||||
|
||||
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
|
||||
|
||||
// `cluster` is only used by `listenInCluster` so for startup performance
|
||||
// reasons it's lazy loaded.
|
||||
var cluster = null;
|
||||
// Lazy loaded to improve startup performance.
|
||||
let cluster;
|
||||
let dns;
|
||||
|
||||
const errnoException = errors.errnoException;
|
||||
const exceptionWithHostPort = errors.exceptionWithHostPort;
|
||||
@ -1034,6 +1033,8 @@ function lookupAndConnect(self, options) {
|
||||
throw new ERR_INVALID_ARG_TYPE('options.lookup',
|
||||
'Function', options.lookup);
|
||||
|
||||
|
||||
if (dns === undefined) dns = require('dns');
|
||||
var dnsopts = {
|
||||
family: options.family,
|
||||
hints: options.hints || 0
|
||||
@ -1368,7 +1369,7 @@ function listenInCluster(server, address, port, addressType,
|
||||
backlog, fd, exclusive) {
|
||||
exclusive = !!exclusive;
|
||||
|
||||
if (cluster === null) cluster = require('cluster');
|
||||
if (cluster === undefined) cluster = require('cluster');
|
||||
|
||||
if (cluster.isMaster || exclusive) {
|
||||
// Will create a new handle
|
||||
@ -1482,6 +1483,7 @@ Server.prototype.listen = function(...args) {
|
||||
};
|
||||
|
||||
function lookupAndListen(self, port, address, backlog, exclusive) {
|
||||
if (dns === undefined) dns = require('dns');
|
||||
dns.lookup(address, function doListen(err, ip, addressType) {
|
||||
if (err) {
|
||||
self.emit('error', err);
|
||||
|
Loading…
Reference in New Issue
Block a user