GeezerVison is showing github.com — Performance issues with connection::request() with HTTP 500 status, delays up to 16 seconds · Issue #1702 · jsforce/jsforce
Performance issues with connection::request() with HTTP 500 status, delays up to 16 seconds #1702DescriptionHi,
I recently faced an issue while doing requests of the following way:
const requestOptions: HttpRequest = {
method: 'GET',
url: `/services/apexrest/website/some-apex-endpoint/${data-id}`,
headers: {
'content-type': 'application/json',
}
};
// ...... some code
const response = await conn.request(requestOptions);
If some-apex-endpoint returns a HTTP 500, the request() call can take up to 16 seconds to return. Adding the option { responseType: 'text' }has had no effect on reducing the execution time.
Replacing the code with a regular Javascript fetch() has reduced the execution back to a more sensible 200 ms average execution time. Activitycristiand391 commented on May 22, 2025 can you set the JSFORCE_LOG_LEVEL=DEBUG env var to see jsforce logs?
jsforce does a retry with exponential backoff on 500 response so that might be the case. pjmlp commented on May 23, 2025 I had a go at it, this was the output redacted,
DEBUG [http-api] <request> method=GET, url=https://salesforce-servername/services/apexrest/website/endpoint/data-id
DEBUG [fetch] retrying for the 1 time
DEBUG [fetch] reason: statusCode match
DEBUG [fetch] retrying for the 2 time
DEBUG [fetch] reason: statusCode match
DEBUG [fetch] retrying for the 3 time
DEBUG [fetch] reason: statusCode match
DEBUG [fetch] retrying for the 4 time
DEBUG [fetch] reason: statusCode match
DEBUG [fetch] retrying for the 5 time
DEBUG [fetch] reason: statusCode match
DEBUG [http-api] elapsed time: 16790 msec
DEBUG [http-api] <response> status=500, url=https://salesforce-servername/services/apexrest/website/endpoint/data-id
Maybe I missed the information on the documentation, is there any way to disable this retry behaviour?
The issue was discovered while dealing with a server that wrongly uses HTTP 500 to mean not found, thus it became quite visible. cristiand391 commented on May 26, 2025 Not doc'd yet, I'll keep this open to track documenting the retry options better.
You can't disable/customize retry options on requests done via conn.data/metadata/sobject/ etc helpers but the conn.request methods take a retry parameter where you can override the default retry options like this:
https://github.com/forcedotcom/agents/blob/834b67ecd4e631a7a57d31da51069425379528ca/src/maybe-mock.ts#L184
default retry opts:
|
statusCodes: options.retry?.statusCodes ?? [420, 429, 500, 502, 503, 504], |
Maybe override just the statusCode array to pass the same defaults without 500? so you still get retries for other requests.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|