From b5f53d9a0bab1c3ff774fbc40a56c1d89dfcff06 Mon Sep 17 00:00:00 2001 From: Paolo Insogna Date: Fri, 26 May 2023 16:28:34 +0200 Subject: [PATCH] net: fix family autoselection SSL connection handling PR-URL: https://github.com/nodejs/node/pull/48189 Backport-PR-URL: https://github.com/nodejs/node/pull/49183 Reviewed-By: James M Snell Reviewed-By: Marco Ippolito --- lib/_tls_wrap.js | 4 ++-- ...est-https-autoselectfamily-slow-timeout.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/internet/test-https-autoselectfamily-slow-timeout.js diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 79be1cc009ec42..5950c52c1dc2ec 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -634,8 +634,8 @@ TLSSocket.prototype._wrapHandle = function(wrap, handle) { }; TLSSocket.prototype[kReinitializeHandle] = function reinitializeHandle(handle) { - const originalServername = this._handle.getServername(); - const originalSession = this._handle.getSession(); + const originalServername = this.ssl ? this._handle.getServername() : null; + const originalSession = this.ssl ? this._handle.getSession() : null; this.handle = this._wrapHandle(null, handle); this.ssl = this._handle; diff --git a/test/internet/test-https-autoselectfamily-slow-timeout.js b/test/internet/test-https-autoselectfamily-slow-timeout.js new file mode 100644 index 00000000000000..ea8f1374c01a23 --- /dev/null +++ b/test/internet/test-https-autoselectfamily-slow-timeout.js @@ -0,0 +1,20 @@ +'use strict'; + +const common = require('../common'); +const { addresses } = require('../common/internet'); + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const assert = require('assert'); +const { request } = require('https'); + +request( + `https://${addresses.INET_HOST}/en`, + // Purposely set this to false because we want all connection but the last to fail + { autoSelectFamily: true, autoSelectFamilyAttemptTimeout: 10 }, + (res) => { + assert.strictEqual(res.statusCode, 200); + res.resume(); + }, +).end();