From a3f587575f8ac2f1f946035788b3b53deb5d94a3 Mon Sep 17 00:00:00 2001 From: Dominik Przybysz Date: Tue, 4 Jul 2023 13:06:53 +0200 Subject: [PATCH] SNOW-734920: Cache HTTPS agent --- lib/http/base.js | 8 ++++++-- lib/http/node.js | 10 ++++++++++ test/integration/testLargeResultSet.js | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/http/base.js b/lib/http/base.js index 9f3302a1c..73757e65f 100644 --- a/lib/http/base.js +++ b/lib/http/base.js @@ -93,8 +93,12 @@ HttpClient.prototype.request = function (options) mock); requestOptions.data = requestOptions.body; - requestOptions.httpsAgent = agentAndProxyOptions.agentClass(agentAndProxyOptions.agentOptions); - requestOptions.httpsAgent.keepAlive = agentAndProxyOptions.agentOptions.keepAlive; + if (agentAndProxyOptions.httpsAgent) { + requestOptions.httpsAgent = agentAndProxyOptions.httpsAgent; + } else { + requestOptions.httpsAgent = agentAndProxyOptions.agentClass(agentAndProxyOptions.agentOptions); + requestOptions.httpsAgent.keepAlive = agentAndProxyOptions.agentOptions.keepAlive; + } requestOptions.retryDelay = this.constructExponentialBackoffStrategy(); request = require('urllib').request(requestOptions.url, requestOptions, async function (err, data, response) diff --git a/lib/http/node.js b/lib/http/node.js index 7d196f21e..6ee040cd3 100644 --- a/lib/http/node.js +++ b/lib/http/node.js @@ -41,12 +41,22 @@ function NodeHttpClient(connectionConfig) Util.inherits(NodeHttpClient, Base); +const defaultHttpsAgentOptions = { keepAlive: true }; +const defaultHttpsAgent = HttpsAgent(defaultHttpsAgentOptions); + /** * @inheritDoc */ NodeHttpClient.prototype.getAgentAndProxyOptions = function (url, proxy, mock) { const isHttps = Url.parse(url).protocol === 'https:'; + + if (isHttps && !proxy && !mock) { + return { + httpsAgent: defaultHttpsAgent, + }; + } + let agentClass; let agentOptions = { keepAlive: true }; let options; diff --git a/test/integration/testLargeResultSet.js b/test/integration/testLargeResultSet.js index 9b82518b9..973a1163e 100644 --- a/test/integration/testLargeResultSet.js +++ b/test/integration/testLargeResultSet.js @@ -263,13 +263,13 @@ describe('SNOW-743920: Large result set with ~35 chunks', function () { before(async () => { connection = testUtil.createConnection(); + configureLogger('TRACE'); await testUtil.connectAsync(connection); // setting ROWS_PER_RESULTSET causes invalid, not encoded chunks from GCP // await testUtil.executeCmdAsync(connection, 'alter session set ROWS_PER_RESULTSET = 1000000'); await testUtil.executeCmdAsync(connection, 'alter session set USE_CACHED_RESULT = false;'); await testUtil.executeCmdAsync(connection, createTable); await testUtil.executeCmdAsync(connection, populateData); - configureLogger('TRACE'); }); after(async () => {