Skip to content

Commit 60eab91

Browse files
BridgeARMylesBorins
authored andcommitted
dns: lazy loaded
PR-URL: #20567 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 28d00a1 commit 60eab91

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/dgram.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const {
3535
ERR_SOCKET_DGRAM_NOT_RUNNING
3636
} = errors.codes;
3737
const { Buffer } = require('buffer');
38-
const dns = require('dns');
3938
const util = require('util');
4039
const { isUint8Array } = require('internal/util/types');
4140
const EventEmitter = require('events');
@@ -47,6 +46,9 @@ const { UV_UDP_REUSEADDR } = process.binding('constants').os;
4746

4847
const { UDP, SendWrap } = process.binding('udp_wrap');
4948

49+
// Lazy load for startup performance.
50+
let dns;
51+
5052
const BIND_STATE_UNBOUND = 0;
5153
const BIND_STATE_BINDING = 1;
5254
const BIND_STATE_BOUND = 2;
@@ -72,9 +74,10 @@ function lookup6(lookup, address, callback) {
7274

7375

7476
function newHandle(type, lookup) {
75-
if (lookup === undefined)
77+
if (lookup === undefined) {
78+
if (dns === undefined) dns = require('dns');
7679
lookup = dns.lookup;
77-
else if (typeof lookup !== 'function')
80+
} else if (typeof lookup !== 'function')
7881
throw new ERR_INVALID_ARG_TYPE('lookup', 'Function', lookup);
7982

8083
if (type === 'udp4') {

0 commit comments

Comments
 (0)