Skip to content

fix: switched from node-fetch to native fetch API @W-23121570@ - #1807

Merged
jfeingold35 merged 28 commits into
mainfrom
d/W-23121570
Jun 25, 2026
Merged

jfeingold35 merged 28 commits into
mainfrom
d/W-23121570

Conversation

@jfeingold35

Copy link
Copy Markdown
Collaborator

Should close #1806 and forcedotcom/cli#3586

@nbolton

nbolton commented Jun 22, 2026

Copy link
Copy Markdown

Nice. For anyone that needs a workaround right now before this lands...

import jsforce from "jsforce";

/**
 * Workaround for jsforce#1806. Node 24.17.0 made keep-alive the default for the global HTTP
 * agents, and jsforce's bundled (unmaintained) node-fetch@2 hangs forever reusing those
 * sockets, so every Salesforce request times out. Forcing `Connection: close` gives each
 * request a fresh socket, which sidesteps it. Delete this file once jsforce#1807 ships and we
 * bump jsforce.
 */

type Connection = InstanceType<typeof jsforce.Connection>;

export async function createSalesforceConnection(
  username: string,
  password: string,
): Promise<Connection> {
  const connection = new jsforce.Connection({});

  const transport = connection._transport;
  const originalHttpRequest = transport.httpRequest.bind(transport);
  transport.httpRequest = (req, options) => {
    req.headers = { ...req.headers, connection: "close" };
    return originalHttpRequest(req, options);
  };

  await connection.login(username, password);
  return connection;
}

Comment thread src/request.ts
if (err instanceof AbortError) {
(err as Error).message += ' Request was aborted due to timeout of 10 minutes.';
let throwableError: Error;
if (err instanceof DOMException && err.name === 'AbortError') {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOMException's message property is not editable, so we just need to construct a new one in this case.

Comment thread .github/workflows/externalNut.yml Outdated
with:
max_attempts: ${{ inputs.attempts }}
command: npm install -g @salesforce/cli@nightly --omit=dev
command: npm install -g @salesforce/cli@dev --omit=dev

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert these?

Comment thread package.json Outdated
@@ -236,8 +236,8 @@
"https-proxy-agent": "^5.0.0",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we're using https-proxy-agent anymore now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

Comment thread src/request.ts Outdated
(err as Error).message += ' Request was aborted due to timeout of 10 minutes.';
let throwableError: Error;
if (err instanceof DOMException && err.name === 'AbortError') {
throwableError = new DOMException((err as Error).message + ' Request was aborted due to timeout of 10 minutes.', (err as Error).name);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my claude is saying default timeout is 30 mins?

Comment thread test/http-api.test.ts
message: 'Invalid AiEvaluation identifier'
}))
const pool = mockAgent.get(loginUrl);
pool.intercept({ path: '/services/data/v59.0', method: 'GET' }).reply(429, JSON.stringify({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my claude is saying:

  - Test error mocks may not match undici's error wrapping — test/http-api.test.ts:104,116,135 — The retry logic expects
  TypeError → cause → SocketError → cause → {code}, but replyWithError(Object.assign(new Error('ECONNRESET'), {code: 
  'ECONNRESET'})) produces a flat error. If tests pass, it's because undici's MockAgent wraps these into TypeErrors, but
  this is fragile and implicit.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried wrapping it in a TypeError and that didn't work, so I think it might actually be correct for it to be unwrapped here. Regardless, I kind of don't want to mess with something that's currently working right now, it that makes any sense.

Comment thread package.json Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more, I don't think we're using nock anymore either, could be worth it to remove and regen package-lock.json after too

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good catch. I'll pull that one too.

WillieRuemmele
WillieRuemmele previously approved these changes Jun 25, 2026
@jfeingold35
jfeingold35 merged commit ccddfee into main Jun 25, 2026
4 of 7 checks passed
@nbolton

nbolton commented Jun 28, 2026

Copy link
Copy Markdown

Thanks for fixing this, guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node.js 24.17.0: jsforce request promise can hang with keep-alive transport

3 participants