Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aaronatbissell opened this issue Jun 17, 2023 · 7 comments
Open
Assignees

Comments

@aaronatbissell
Copy link

aaronatbissell commented Jun 17, 2023

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
Copy link
Author

aaronatbissell commented Jun 17, 2023

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
Copy link
Member

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

@sunil-lakshman
Copy link
Contributor

@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:

  • Uses exponential backoff logic.
  • Delay is calculated as 0.25 * Math.pow(2, retryCount) * this.SEC_TO_MS.
  • For each retry, the delay increases exponentially.
  • Example delays:
    • Retry 0:
      • 0.25 * Math.pow(2, 0) * 1000 = 250 ms
    • Retry 1:
      • 0.25 * Math.pow(2, 1) * 1000 = 500 ms
    • Retry 2:
      • 0.25 * Math.pow(2, 2) * 1000 = 1000 ms
    • Retry 3:
      • 0.25 * Math.pow(2, 3) * 1000 = 2000 ms
    • Retry 4:
      • 0.25 * Math.pow(2, 4) * 1000 = 4000 ms
this.client = contentstack.client({
  retryLimit: 4,
  timeout: 60 * this.SEC_TO_MS,
  retryDelayOptions: {
    customBackoff: (retryCount, _error) => 1000 * retryCount,
  },
});

Custom Backoff Calculation:

  • Uses linear backoff logic.
  • Delay is calculated as 1000 * retryCount.
  • For each retry, the delay increases linearly.
  • Example delays:
    • Retry 0:
      • 1000 * 0 = 0 ms
    • Retry 1:
      • 1000 * 1 = 1000 ms
    • Retry 2:
      • 1000 * 2 = 2000 ms
    • Retry 3:
      • 1000 * 3 = 3000 ms
    • Retry 4:
      • 1000 * 4 = 4000 ms

Summary:

  • First Snippet:

    • Exponential backoff: Delays increase exponentially with each retry.
    • Typically used to more quickly mitigate transient errors by progressively increasing delay.
  • Second Snippet:

    • Linear backoff: Delays increase linearly with each retry.
    • Simpler, and delays increase at a constant rate.

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
Copy link
Author

aaronatbissell commented Aug 5, 2024

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
Copy link
Author

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

@cs-raj
Copy link
Contributor

cs-raj commented Sep 11, 2024

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

@vkalta
Copy link

vkalta commented Dec 12, 2024

Hi @aaronatbissell , apologies for inconvenience. I have found a fix for this issue and the PR can be found here https://contentstack.atlassian.net/browse/DX-1409.
Its currently being reviewed.
Thanks for your patience.

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

No branches or pull requests

5 participants