contentstack / contentstack-management-javascript

Javascript SDK for Contentstack’s Content Management API (Nodejs)
MIT License
4 stars 7 forks source link

Custom backoff in retryDelayOptions doesn't change the 300ms delay #55

Open aaronatbissell opened 1 year ago

aaronatbissell commented 1 year ago

The customBackoff function that can be passed to retryDelayOptions doesn't appear to change the retry delay at all. The delay still appears to be 300ms no matter what. The message printed on screen also indicates 300ms no matter what.

Here's the client we are using:

this.client = contentstack.client({
      retryLimit: 4,
      timeout: 60 * this.SEC_TO_MS,
      /**
       * Exponential backoff logic:
       * retry  |  total elapsed time since original request (sec)
       * 0      |  0.000
       * 1      |  0.250
       * 2      |  0.750
       * 3      |  1.750
       * 4      |  3.750
       */
      retryDelayOptions: {
        customBackoff: (retryCount, _error) =>
          0.25 * Math.pow(2, retryCount) * this.SEC_TO_MS,
      },
    });
aaronatbissell commented 1 year ago

Even if you make it something simple like this, it still only waits for 300ms

this.client = contentstack.client({
      retryLimit: 4,
      timeout: 60 * this.SEC_TO_MS,
      retryDelayOptions: {
        customBackoff: (retryCount, _error) => 1000 * retryCount,
      },
    });
ishaileshmishra commented 1 year ago

thanks for raising the issue, We will look into it @aaronatbissell.

sunil-lakshman commented 1 month ago

@aaronatbissell The main difference between the two code snippets is how the customBackoff function calculates the retry delay.

this.client = contentstack.client({
  retryLimit: 4,
  timeout: 60 * this.SEC_TO_MS,
  /**
   * Exponential backoff logic:
   * retry  |  total elapsed time since original request (sec)
   * 0      |  0.000
   * 1      |  0.250
   * 2      |  0.750
   * 3      |  1.750
   * 4      |  3.750
   */
  retryDelayOptions: {
    customBackoff: (retryCount, _error) =>
      0.25 * Math.pow(2, retryCount) * this.SEC_TO_MS,
  },
});

Custom Backoff Calculation:

this.client = contentstack.client({
  retryLimit: 4,
  timeout: 60 * this.SEC_TO_MS,
  retryDelayOptions: {
    customBackoff: (retryCount, _error) => 1000 * retryCount,
  },
});

Custom Backoff Calculation:

Summary:

Depending on your needs, you might prefer one method over the other. Exponential backoff is generally more effective at handling temporary server overloads, while linear backoff is simpler and may be suitable for other types of retries.

aaronatbissell commented 1 month ago

I understand the difference between exponential and linear back-off.

The problem was that no matter what you put as the customBackoff function, it will always wait for 300ms (and the statement that gets printed to the screen always says "waiting 300ms")

~Note: this issue is over a year old and I haven't tested to see if this is STILL an issue~

Just tested - this still appears to be an issue with v1.17.0

aaronatbissell commented 1 month ago

Here's a repo that reproduces the issue: https://github.com/aaronatbissell/contentstack-management-javascript-issue-55

cs-raj commented 2 weeks ago

Hi @aaronatbissell we will be looking into the issue as earliest as possible and we have taken it in the upcoming sprint. We will post the reply once fixed cc: @harshithad0703 @sunil-lakshman @netrajpatel @shafeeqd959