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_BAD_PORT,
|
||||||
ERR_SOCKET_CLOSED
|
ERR_SOCKET_CLOSED
|
||||||
} = errors.codes;
|
} = errors.codes;
|
||||||
const dns = require('dns');
|
|
||||||
|
|
||||||
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
|
const kLastWriteQueueSize = Symbol('lastWriteQueueSize');
|
||||||
|
|
||||||
// `cluster` is only used by `listenInCluster` so for startup performance
|
// Lazy loaded to improve startup performance.
|
||||||
// reasons it's lazy loaded.
|
let cluster;
|
||||||
var cluster = null;
|
let dns;
|
||||||
|
|
||||||
const errnoException = errors.errnoException;
|
const errnoException = errors.errnoException;
|
||||||
const exceptionWithHostPort = errors.exceptionWithHostPort;
|
const exceptionWithHostPort = errors.exceptionWithHostPort;
|
||||||
@ -1034,6 +1033,8 @@ function lookupAndConnect(self, options) {
|
|||||||
throw new ERR_INVALID_ARG_TYPE('options.lookup',
|
throw new ERR_INVALID_ARG_TYPE('options.lookup',
|
||||||
'Function', options.lookup);
|
'Function', options.lookup);
|
||||||
|
|
||||||
|
|
||||||
|
if (dns === undefined) dns = require('dns');
|
||||||
var dnsopts = {
|
var dnsopts = {
|
||||||
family: options.family,
|
family: options.family,
|
||||||
hints: options.hints || 0
|
hints: options.hints || 0
|
||||||
@ -1368,7 +1369,7 @@ function listenInCluster(server, address, port, addressType,
|
|||||||
backlog, fd, exclusive) {
|
backlog, fd, exclusive) {
|
||||||
exclusive = !!exclusive;
|
exclusive = !!exclusive;
|
||||||
|
|
||||||
if (cluster === null) cluster = require('cluster');
|
if (cluster === undefined) cluster = require('cluster');
|
||||||
|
|
||||||
if (cluster.isMaster || exclusive) {
|
if (cluster.isMaster || exclusive) {
|
||||||
// Will create a new handle
|
// Will create a new handle
|
||||||
@ -1482,6 +1483,7 @@ Server.prototype.listen = function(...args) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function lookupAndListen(self, port, address, backlog, exclusive) {
|
function lookupAndListen(self, port, address, backlog, exclusive) {
|
||||||
|
if (dns === undefined) dns = require('dns');
|
||||||
dns.lookup(address, function doListen(err, ip, addressType) {
|
dns.lookup(address, function doListen(err, ip, addressType) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.emit('error', err);
|
self.emit('error', err);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user