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

Retries issues #104

Closed
Arjunalapsapkota opened this issue Apr 20, 2020 · 7 comments
Closed

Retries issues #104

Arjunalapsapkota opened this issue Apr 20, 2020 · 7 comments

Comments

@Arjunalapsapkota
Copy link

By default , retry count is set to 3. But It's only trying two times. Doesn't have any effect if I define it to be 3, 4 or 5. It only tries 2 times. Please fix this issue. Thanks

@khitrenovich
Copy link

khitrenovich commented Jun 17, 2020

Possible duplicate of #68

I spent some time diving into the problem (as I saw the same happening in one of my projects) and figured out that response interceptor installed by retry-axios is not being called on the second attempt, causing the failure to propagate immediately instead of retrying. This is likely a regression introduced in v0.19.x of axios, as mentioned in https://github.com/chinesedfan/You-Dont-Know-Axios#config-defaults:

0.19, introduces a new util method called deepMerge, which will clone the object when replacing, but with some bugs. Arrays are cloned as objects. Some config fields (i.e. params) should be supported deep merging but not, and custom default fields are lost totally.

Downgrading axios to v0.18.1 solved the issue for me.

@quang-m-nguyen
Copy link

quang-m-nguyen commented Jun 30, 2020

downgrading worked for me. thanks @khitrenovich !

but the retries count here stays at 1 regardless of how many retries I gave it

@moltar
Copy link

moltar commented Aug 19, 2020

Seeing this too. The setting has no effect and only 2 attempts are tried.

Edit: I tried all versions, including the 0.20 beta, and 0.18 downgrade

@sk-
Copy link

sk- commented Aug 24, 2020

@moltar How did you set up the raxConfig? I'm asking because I identified issue #124, in which if you use a custom axios instance, then it won't work unless you also specify the instance field.

@reisandbeans
Copy link

I was having a similar problem using the following setup:

const instance = Axios.create();
instance.defaults.raxConfig = { ... };
instance.get(...)

Changing the values in raxConfig above was having no effect. When I saw this ticket, I noticed I was using axios 0.19 and updated it to axios 0.21, which solved the problem for me

@JustinBeckwith
Copy link
Owner

So this is a little confusing :) One thing to look out for here, are that there are separate settings for retry and noResponseRetries. The retry number will be used if you connect to the endpoint, and get a non-2xx response. The noResponseRetries is specifically used in the case where the connection was never made, like ETIMEDOUT or ENOTFOUND errors.

To get it to use 3 retries every time (regardless of the reason it fails), this ought to work:

const rax = require('retry-axios');
const axios = require('axios');

rax.attach();

async function main() {
  try {
    await axios({
      url: 'https://test.local',
      raxConfig: {
        retry: 3,
        noResponseRetries: 3,
        onRetryAttempt: err => {
          const cfg = rax.getConfig(err);
          console.log(`Retry attempt #${cfg.currentRetryAttempt}`);
        }
      },
    });
  } catch (err) {
    console.error(err);
  }
}
main();

Note, this is using:

  • Node.js 14.17..3
  • axios 0.21.1
  • retry-axios 2.5.0

For anyone else that comes here - please make sure to post the exact code you're using :) Also, it would be helpful to include the versions of axios and retry-axios, as well as the error you're getting when the request fails.

@orgads
Copy link
Contributor

orgads commented Nov 16, 2023

It works with the default axios, but doesn't work with axios instance (axios.create()). See #68 (comment)

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

8 participants