I am in the process of upgrading a job script that previously ran using NodeJS 16.x, upgrading to NodeJS 22.x.
This is a pretty simple script that contains some API calls to GitHub using Octokit. The issue is that when running this script using Node 22, I am now getting TLS errors where It was not previously. This script is executed behind an enterprise proxy.
Sample code: package.json
"dependencies": {
"https-proxy-agent": "7.0.6",
"node-fetch": "3.3.2",
"octokit": "5.0.2"
}
index.js
const { HttpsProxyAgent } = require("https-proxy-agent");
const { Octokit } = require("octokit");
async function main(argv) {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
const token = process.env["AUTH_TOKEN"];
const testProxy = process.env["HTTPS_PROXY"];
const testProxyAgent = new HttpsProxyAgent(testProxy);
// TEST #1: Using fetch to make a request
const testHeaders = {
Authorization: `bearer ${token}`,
"Content-Type": "application/json",
};
const test1Response = await fetch(
"https://api.github.com/repos/<my org>/<my repo>",
{
method: "GET",
headers: testHeaders,
agent: testProxyAgent,
},
);
const test1ResponseText = await test1Response.text();
console.log(`Response #1: [${test1ResponseText}]`);
// TEST #2: Using Octokit to make a request
const testGithubClient = new Octokit({
auth: token,
request: {
agent: testProxyAgent,
},
});
const test2response = await testGithubClient.rest.repos.get({
owner: "<my org>",
repo: "<my repo>",
});
console.log(`Response #2: [${JSON.stringify(test2response.data)}]`);
}
Test #1 above works fine and produces the expected result. Test #2 produces an error:
RequestError [HttpError]: Client network socket disconnected before secure TLS connection was established
<stack_trace>
status: 500,
I'm clearly using a proxy for both calls but is Octokit not handling the proxy correctly?