Skip to content

Performance issues with connection::request() with HTTP 500 status, delays up to 16 seconds #1702

Open

Description

@pjmlp

Hi,

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.

Activity

  1. cristiand391 commented on May 22, 2025

    @cristiand391
    Contributor

    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.

  2. pjmlp commented on May 23, 2025

    @pjmlp
    Author

    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.

  3. added
    docs
    and removed on May 26, 2025
  4. cristiand391 commented on May 26, 2025

    @cristiand391
    Contributor

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions