Git Product home page Git Product logo

Comments (18)

rubennorte avatar rubennorte commented on September 3, 2024 19

As stated in a PR that was adding that as a configuration (which was rejected as we're trying to keep the API minimal), you can still retry timeout errors using the built-in functions with way:

retryCondition: (error) => {
  return axiosRetry.isNetworkOrIdempotentRequestError(error)
    || error.code === 'ECONNABORTED';
}

from axios-retry.

antony avatar antony commented on September 3, 2024 13

Thanks @erdii - that issue doesn't make any sense at all. Timeouts should definitely be retried. For us at least, it's the only reason we want to retry!

from axios-retry.

erdii avatar erdii commented on September 3, 2024 9

A new option retryCondition (Default: error => !error.response) has been added.
This issue can be closed now, am I right?

Thank you @rubennorte!

Edit: I still cannot use the retryCondition function to retry ECONNABORTED requests because of this guy here:

const shouldRetry = retryCondition(error)
      && error.code !== 'ECONNABORTED'
      && config.retryCount < retries
      && isRetryAllowed(error);

shouldn't this be:

const shouldRetry = retryCondition(error)
      && config.retryCount < retries;

and the default retryCondition something like error => !error.response && isRetryAllowed(error) && error.code !== 'ECONNABORTED'?

EDIT2: add forgotten ECONNABORTED handling
EDIT3: I'd happily create a pull request containing the code changes and tests if you approve this change

from axios-retry.

Lxxyx avatar Lxxyx commented on September 3, 2024 7

Add a new config? retryOnTimeout, set default to false.

In someway, timeout means I wants to cancel this request and retry.

from axios-retry.

rubennorte avatar rubennorte commented on September 3, 2024 6

We're going to make some changes in the library soon, including one to solve this issue. What do you think about:

import axios from 'axios';
import axiosRetry from 'axios-retry';

axiosRetry(axios, {
  retryCondition: axiosRetry.isNetworkError, // default
  retryCondition: axiosRetry.isAnyError // alternative
  retryCondition: (response) => {  // custom
    return axiosRetry.isNetworkError(response) || response.config.method === 'GET'
  }
});

from axios-retry.

antony avatar antony commented on September 3, 2024 6

Seems reasonable to me @rubennorte. I'd also recommend adding some sort of retryDelay parameter which can be a simple number, or a function which is passed the last error, and the current retry count, allowing for exponential decays, thus:

// with retries: 7, retries 7 times with a 1 second gap.
retryDelay: 1000

// for timeouts, wait longer before retrying. For all other errors, just 1 second.
retryDelay: (error) => { return (error.message === 'ETIMEDOUT') ? 60000 : 1000 }

// linear decay
retryDelay: (error, count) => { return count * 1000 }

// exponential decay
retryDelay: (error, count) => { return (count * count) * 1000 }

Maybe this is a new feature rather than an addition to this one, but it's something got has built in - and ultimately was our reason for switching to it. We really want our payloads to go through, and our providers (banks!) are super-flaky sometimes.

from axios-retry.

raychenfj avatar raychenfj commented on September 3, 2024 4

Hi @rubennorte,

I check you latest version, but this line still prevent it retry on timeout.

error.code !== 'ECONNABORTED'

I think put it into the default retryCondition is a better idea, so anyone doesn't need it can override it. I can send a PR if you need.

export function isNetworkError(error) {
  return !error.response && error.code !== 'ECONNABORTED';
}

Thanks for making this lib, I use it in my projects, but I have to make a copy and remove that line every time., it's really inconvenient.

from axios-retry.

tatianajiselle avatar tatianajiselle commented on September 3, 2024 4

Weird, ive implemented the override via retryCondition() with return true and my retries dont trigger.


RESOLVED:

full config.. im using nestjs so access to axios is through the httpService reference and configuring a http agent timeout...

After some debugging I realized that for this to work, shouldRetryOnTimeout need to be set to true, otherwise the timeout which is inherited by the http module agent configuration ends up timing out and the retry condition never triggers.

hopefully this will help someone else!

axiosRetry(httpService.axiosRef, {
            retries: 3,
            retryDelay: () => 100, // in milliseconds
            shouldResetTimeout: true,
            retryCondition: (error: AxiosError) => {
                return (
                    isNetworkOrIdempotentRequestError(error) ||
                    error.code === "ECONNABORTED"
                );
            },
...
}

from axios-retry.

erdii avatar erdii commented on September 3, 2024 3

I'm a bit busy right now - but I have school next week so I'll have plenty of time to implement it and create a pull request. Is this ok? @Lxxyx @antony ?

@rubennorte are you willing to accept my pr when i provide test coverage and doc updates? :)

from axios-retry.

erdii avatar erdii commented on September 3, 2024

I think this is because of #5

from axios-retry.

erdii avatar erdii commented on September 3, 2024

I'm testing the lib right now and it seems that it doesn't retry if you disconnect from the network (on mobile) at all.

maybe we should give tomaash/axios-status a try. (even though it changes the request interface)

from axios-retry.

antony avatar antony commented on September 3, 2024

I've had to revert back to got right now because this transition is taking too long. next time I venture into it I will look at axios-status so thanks for that!

from axios-retry.

rubennorte avatar rubennorte commented on September 3, 2024

The error that's being specifically ignored in the code is ECONNABORTED, which means that the program itself cancelled the request due to a specific cancellation or a timeout. What use case do you have that you need to retry those? Why don't you simply increment the timeout?

Retrying on timeout could make requests too slow, as if something goes wrong you'll be paying the cost of the timeout for each call.

from axios-retry.

antony avatar antony commented on September 3, 2024

What we do is talk to a variety of different bank APIs to get loans. Some of these APIs can take upto 2 minutes to reply, and often they will take longer. What we do is set our timeout to 2 minutes, and if they take longer, we just retry the request. We do this up to 5 times before giving up.

With got (native)/request (requestretry) this is no problem, but I'd like to switch to axios - however this ECONNABORTED check prevents me from doing so.

from axios-retry.

Lxxyx avatar Lxxyx commented on September 3, 2024

@erdii idea is great. Can you change the code? @antony

from axios-retry.

antony avatar antony commented on September 3, 2024

Yes @erdii - this is exactly what I was suggesting. To be able to configure the retry conditions in this way is absolutely critical.

from axios-retry.

erdii avatar erdii commented on September 3, 2024

I have implemented the changes, tests, and documentation at erdii@25faf8f. Creating a pull request now.

from axios-retry.

jony89 avatar jony89 commented on September 3, 2024

@rubennorte

Still I can't use the lib implementation overall.

isNetworkError, isSafeRequestError and isIdempotentRequestError still checks for :

error.code !== 'ECONNABORTED'

This error code received when defining axios a timeout, and it has passed.
This is like the most wanted scenario to retry.

So currently I still cant use this function implementation.

Maybe you could have a configuration option to decide whether or not to check for ECONNABORTED ?

from axios-retry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.