-
Notifications
You must be signed in to change notification settings - Fork 167
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
Doesn't retry on timeout #8
Comments
I think this is because of #5 |
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! |
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) |
I've had to revert back to |
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. |
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. |
Add a new config? retryOnTimeout, set default to false. In someway, timeout means I wants to cancel this request and retry. |
A new option Thank you @rubennorte! Edit: I still cannot use the retryCondition function to retry ECONNABORTED requests because of this guy here:
shouldn't this be:
and the default EDIT2: add forgotten ECONNABORTED handling |
Yes @erdii - this is exactly what I was suggesting. To be able to configure the retry conditions in this way is absolutely critical. |
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? :) |
I have implemented the changes, tests, and documentation at erdii@25faf8f. Creating a pull request now. |
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'
}
}); |
Seems reasonable to me @rubennorte. I'd also recommend adding some sort of
Maybe this is a new feature rather than an addition to this one, but it's something |
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. |
Still I can't use the lib implementation overall.
error.code !== 'ECONNABORTED' This error code received when defining axios a timeout, and it has passed. So currently I still cant use this function implementation. Maybe you could have a configuration option to decide whether or not to check for |
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';
} |
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, hopefully this will help someone else!
|
I think the title explains it. The code specifies
and there is no way to override it.
Retrying when an endpoint timeouts is pretty much our only use for a retry module. I'd like to be able to override all the retry conditions - but I'm also confused as to why we wouldn't retry on a timeout in the first place?
The text was updated successfully, but these errors were encountered: