diff --git a/lib/core/connection/connect.js b/lib/core/connection/connect.js index 2922c61b45..b096e21fbc 100644 --- a/lib/core/connection/connect.js +++ b/lib/core/connection/connect.js @@ -281,6 +281,7 @@ function makeConnection(family, options, cancellationToken, _callback) { socket.setTimeout(connectionTimeout); socket.setNoDelay(noDelay); + const connectEvent = useSsl ? 'secureConnect' : 'connect'; let cancellationHandler; function errorHandler(eventName) { return err => { @@ -289,7 +290,7 @@ function makeConnection(family, options, cancellationToken, _callback) { cancellationToken.removeListener('cancel', cancellationHandler); } - socket.removeListener('connect', connectHandler); + socket.removeListener(connectEvent, connectHandler); callback(connectionFailureError(eventName, err)); }; } @@ -314,7 +315,7 @@ function makeConnection(family, options, cancellationToken, _callback) { cancellationToken.once('cancel', cancellationHandler); } - socket.once('connect', connectHandler); + socket.once(connectEvent, connectHandler); } const CONNECTION_ERROR_EVENTS = ['error', 'close', 'timeout', 'parseError'];