From 72c2a5149c6419a720a34190b2c8e79416dc4280 Mon Sep 17 00:00:00 2001 From: Benjamin Gruenbaum Date: Sun, 30 Jan 2022 14:03:46 +0200 Subject: [PATCH] lazy-load tls (#1186) --- lib/core/connect.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/connect.js b/lib/core/connect.js index 951bf7c2ea7..eafc33b7423 100644 --- a/lib/core/connect.js +++ b/lib/core/connect.js @@ -1,10 +1,10 @@ 'use strict' const net = require('net') -const tls = require('tls') const assert = require('assert') const util = require('./util') const { InvalidArgumentError, ConnectTimeoutError } = require('./errors') +let tls // include tls conditionally since it is not always available // TODO: session re-use does not wait for the first // connection to resolve the session and might therefore @@ -24,6 +24,9 @@ function buildConnector ({ maxCachedSessions, socketPath, timeout, ...opts }) { return function connect ({ hostname, host, protocol, port, servername }, callback) { let socket if (protocol === 'https:') { + if (!tls) { + tls = require('tls') + } servername = servername || options.servername || util.getServerName(host) || null const sessionKey = servername || hostname