Repository navigation
Description
Hello, I have a problem. I am using jsforce version 1.11 on my project. Now I decided to upgrade to version 3 and encountered an error.
My code creates a new connection, passing in a perfectly valid refreshToken and instanceUrl. The passed instanceUrl is valid, but not the one returned by Salesforce.
For example, I have an instanceUrl:
https://mdc-hause.my.salesforce.com
JsForce V1 and Salesforce CLI work with this URL.
I get the following URL when creating a connection:
https://someKey-playground1.my.salesforce.com
Note: These URLs are provided as an example to show that they are the same org. Salesforce previously replaced one with the other, so they both work. However, JsForce V3 doesn't work with the older one.
However, when attempting to make a request on this connection, the .on('refresh') event is called indefinitely:
const creds = {
oauth2: {
validClientId,
validClientSecret,
},
refreshToken: validRefreshToken,
instanceUrl: validProperInstanceUrl,
version: '60.0',
};
connection = new jsforce.Connection(creds);
connection.on('refresh', (accessToken) => {
console.log('instanceUrl', connection.instanceUrl);
// Here, the connection already has an refreshed instanceUrl. This log is reproduced endlessly.
});
const q = connection.query(someQuery)
.on('record', (record) => {
records.push(record);
})
.on('end', () => {
resolve(records);
})
.on('error', (error) => {
reject(error);
});
console.log('Before query run');
q.run(JSFORCE_OPTIONS)
.catch((err) => {
reject(err);
});
However, when I try to execute the request, the 'refresh' event occurs again and again, and the request fails. In the terminal, I see the following:
Before query run
instanceUrl https://someKey-playground1.my.salesforce.com
instanceUrl https://someKey-playground1.my.salesforce.com
instanceUrl https://someKey-playground1.my.salesforce.com
instanceUrl https://someKey-playground1.my.salesforce.com
instanceUrl https://someKey-playground1.my.salesforce.com
......
Note: The above code works for jsforce V1.
Activity
cristiand391 commentedon Oct 20, 2025
hey 👋🏼
a few questions:
in this block:
validProperInstanceUrlthe old my domain URL or the latest one?Matthew-Zvantsov commentedon Oct 21, 2025
Hi!
Matthew-Zvantsov commentedon Nov 3, 2025
@cristiand391 I wanted to check in to see if anyone had a chance to look at my question above. Thanks in advance!
amitbeck commentedon Feb 5, 2026
In my case the issue was that I was using OAuth2 credentials for the wrong instance (production instance URL instead of sandbox instance URL).
Kinda surprised it was stuck in a
refreshevent loop instead of the connection APIs rejecting...cristiand391 commentedon Feb 5, 2026
@amitbeck the request was probably returning the status code/response that triggers a session-refresh.
If you can reproduce it with this env var set
JSFORCE_LOG_LEVEL=DEBUGand share the request details when it gets stuck I can look into it (you can redact org instances URLs, we only care about the response status code)