softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.87k stars 165 forks source link

What is the initial retry delay #243

Closed Stevemoretz closed 12 months ago

Stevemoretz commented 12 months ago

Using Apollo's retry for instance you can define an initial retry time.

        new RetryLink({
            delay: {
                initial: 1500,
            },
        }),

While this library, doesn't have that option at least it would be nice to mention what the initial time is by default adding an option to change it however would be awesome.

Stevemoretz commented 12 months ago

Just by skimming your code, it's probably 100ms?

https://github.com/softonic/axios-retry/blob/f583f616dbc0d90b8740046ead342f1e29b9fe44/es/index.mjs#L81

yutak23 commented 12 months ago

According to README, the default retryDelay time is 0.

image

So I think we need to implement the function as follows.

axiosRetry(axios, { retryDelay: () => return 1500 });

Just by skimming your code, it's probably 100ms?

Since it is an Exponential Backoff, I believe the Delay time is not constant but increases exponentially. https://cloud.google.com/iot/docs/how-tos/exponential-backoff

Stevemoretz commented 12 months ago

According to README, the default retryDelay time is 0.

image

So I think we need to implement the function as follows.

axiosRetry(axios, { retryDelay: () => return 1500 });

Just by skimming your code, it's probably 100ms?

Since it is an Exponential Backoff, I believe the Delay time is not constant but increases exponentially. https://cloud.google.com/iot/docs/how-tos/exponential-backoff

Thanks so much for the detailed explanation, and sorry I forgot to mention I was using the exponential, and using that the delay changes as you mentioned but what I was after was the initial delay for instance :

If the initial delay is 1s. The delays will be : 1s,2s,4s,... If the initial delay is 2s. The delays will be : 2s,4s,8s,...

So essentially the initial delay is responsible for how slow or fast the retries happen.

yutak23 commented 12 months ago

If the initial delay is 1s. The delays will be : 1s,2s,4s,... If the initial delay is 2s. The delays will be :2s,4s,8s,...

So essentially the initial delay is responsible for how slow or fast the retries happen.

If such behavior is desired, one answer seems to be to implement the following.

const initialDelay = 2;

axiosRetry(axios, { retryDelay: (retryNumber) => return Math.pow(initialDelay, retryNumber) });
Stevemoretz commented 12 months ago

Thanks! Makes sense, closing :)