Skip to content

Commit

Permalink
SNOW-734920: Cache HTTPS agent
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-dprzybysz committed Aug 21, 2023
1 parent c75d179 commit a3f5875
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/http/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions lib/http/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/integration/testLargeResultSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit a3f5875

Please sign in to comment.