From 678962efb3696336f2779def3c8ebde7ed531542 Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Wed, 19 Dec 2018 14:42:58 -0800 Subject: [PATCH] tls: do not confuse TLSSocket and Socket MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't use "socket" to describe two different objects in the same function. PR-URL: https://github.com/nodejs/node/pull/25153 Reviewed-By: Anna Henningsen Reviewed-By: Tobias Nießen Reviewed-By: James M Snell Reviewed-By: Anatoli Papirovski --- lib/_tls_wrap.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 8a3ef7b9401daa..4cee805e967b13 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -1126,7 +1126,7 @@ exports.connect = function connect(...args) { const context = options.secureContext || tls.createSecureContext(options); - var socket = new TLSSocket(options.socket, { + var tlssock = new TLSSocket(options.socket, { pipe: !!options.path, secureContext: context, isServer: false, @@ -1137,12 +1137,14 @@ exports.connect = function connect(...args) { requestOCSP: options.requestOCSP }); - socket[kConnectOptions] = options; + tlssock[kConnectOptions] = options; if (cb) - socket.once('secureConnect', cb); + tlssock.once('secureConnect', cb); if (!options.socket) { + // If user provided the socket, its their responsibility to manage its + // connectivity. If we created one internally, we connect it. const connectOpt = { path: options.path, port: options.port, @@ -1152,22 +1154,22 @@ exports.connect = function connect(...args) { localPort: options.localPort, lookup: options.lookup }; - socket.connect(connectOpt, socket._start); + tlssock.connect(connectOpt, tlssock._start); } - socket._releaseControl(); + tlssock._releaseControl(); if (options.session) - socket.setSession(options.session); + tlssock.setSession(options.session); if (options.servername) - socket.setServername(options.servername); + tlssock.setServername(options.servername); if (options.socket) - socket._start(); + tlssock._start(); - socket.on('secure', onConnectSecure); - socket.once('end', onConnectEnd); + tlssock.on('secure', onConnectSecure); + tlssock.once('end', onConnectEnd); - return socket; + return tlssock; };