softonic / axios-retry

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

All retries have timeout of 1ms set despite not being set anywhere that way #242

Open canpoyrazoglu opened 1 year ago

canpoyrazoglu commented 1 year ago

We have the following configuration:

axiosRetry(axiosInstance, { retries: 3 });

~However, it never tries to retry. I also tried adding a onRetry handler, putting a console log inside. It never gets hit either, confirming that it indeed never retries.~

~When I override retryCondition it does get triggered though if I try to call isNetworkOrIdempotentRequestError with the error in the callback, I get Cannot read property 'status' of undefined.~

After a failed request, axios-retry is retrying all requests with 1ms timeout, causing all of them to fail repeatedly.

What am I doing wrong?

(React Native 0.71.6, axios 0.27.2, axios-retry 3.3.1)

yutak23 commented 1 year ago

it never tries to retry.

Can you provide details of the error when it does not retry so that we can better clarify the issue?

canpoyrazoglu commented 1 year ago

After digging deeper I've realized that the error Cannot read property 'status' of undefined is actually throwing at a place that a colleague wrote long time ago. I've fixed it, however, the issue still continues with another error. First, here is my original request:

{
   "message":"timeout of 2000ms exceeded",
   "name":"AxiosError",
   "config":{
      "transitional":{
         "silentJSONParsing":true,
         "forcedJSONParsing":true,
         "clarifyTimeoutError":false
      },
      "transformRequest":[
         null
      ],
      "transformResponse":[
         null
      ],
      "timeout":1,
      "xsrfCookieName":"XSRF-TOKEN",
      "xsrfHeaderName":"X-XSRF-TOKEN",
      "maxContentLength":-1,
      "maxBodyLength":-1,
      "env":{
         "FormData":null
      },
      "headers":{
         "Accept":"application/json, text/plain, */*",
         "user-device-id":"[redacted]",
         "x-client-version":"1.0.17",
         "Authorization":"Bearer [redacted]",
         "x-locale":"es"
      },
      "baseURL":"https://[redacted]",
      "method":"get",
      "url":"[redacted]",
      "axios-retry":{
         "retryCount":1,
         "lastRequestTime":1693897894950
      }
   },
   "code":"ECONNABORTED",
   "status":null
}

Notice that it has a timeout of 2000ms (normally it's 12 seconds though I reduced it temporarily for testing this issue). After the requests fail, I get this:

timeout of 1ms exceeded

Why is it trying again with a 1ms timeout? After initial (failing) request, it will (obviously) always fail again as timeout is 1ms. I think exponential backoff would be more appropriate.

My observation is that after initial (real request, made by me, not axios-retry) the timeout is set correctly at what I've provided. However, all the subsequent requests (the retry requests made by axios-retry) have a timeout set to 1ms, failing in rapid succession.

I'm not setting timeout anywhere to 1ms. THe only reference to timeout (either in axios or axios-retry in total) is only where I create axios instance:

Axios.create({
  baseURL: Config.API_URL,
  timeout: 2000,
  headers: {
    [...]
  },
});

So even if the error in my original issue was misleading, the actual issue remains. (I've updated the original issue and title to reflect the actual problem)

mishagale commented 8 months ago

I suspect this might be caused by not setting the shouldResetTimeout flag to true.