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

Does not retry on timeout #133

Open
some-user123 opened this issue Dec 4, 2020 · 4 comments
Open

Does not retry on timeout #133

some-user123 opened this issue Dec 4, 2020 · 4 comments

Comments

@some-user123
Copy link

I'm using retry-axios succesfully to retry on server-side errors like 5xx responses.
However, I'm also experiencing sporadically timeouts on the server-side. In this cases, there is no retry attempt.

I would consider timeouts a service-side error as well. Shouldn't there be a retry attempt?

@Grundlefleck
Copy link

I had a similar issue and found that I needed to pass e.g. { timeout: 3_000 } to Axios itself, and combine that with the noResponseRetries: 3 options of this retry-axios library.

HTH

@Naramsim
Copy link

@Grundlefleck Can you provide an example? Using your settings, it didn't trigger a retry.

@Grundlefleck
Copy link

@Naramsim
Here's an attempt at an SSCCE:

axios v0.21.1
retry-axios v2.4.0
node v14.2.0
(TypeScript but it shouldn't matter)

/* eslint-disable */
import axios from "axios";
import * as rax from "retry-axios";

const axiosInstance = axios.create({
  timeout: 2_000
});
axiosInstance.defaults.raxConfig = {
  retry: 3,
  noResponseRetries: 3,
  instance: axiosInstance,
  onRetryAttempt: (err) => {
    const retryAttempt = rax.getConfig(err)!.currentRetryAttempt!;
    console.log(`Retry attempt #${retryAttempt}. Error: ${err.code}: ${err.message}`);
  }
};
rax.attach(axiosInstance);

void axiosInstance
  .get("http://google.com:2013/") // Happens to be a URL that always times out
  .then(() => console.log("Request(s) successful"))
  .catch((error) => {
    console.log("Request(s) failed");
    console.error(error.message);
  });

Results in output:

Retry attempt #1. Error: ECONNABORTED: timeout of 2000ms exceeded
Retry attempt #2. Error: ECONNABORTED: timeout of 2000ms exceeded
Retry attempt #3. Error: ECONNABORTED: timeout of 2000ms exceeded
Request(s) failed
timeout of 2000ms exceeded

Without timeout: 2_000 given to axios.create() this example takes a several minutes to timeout, but it still does retry.

I also discovered that the actual retries attempted is essentially Math.min(raxConfig.retry, raxConfig.noResponseRetries). Doesn't seem we can specify noResponseRetries independently of retry.

@Naramsim
Copy link

Thanks @Grundlefleck

In the end, I switched to Got. It has the retry mechanism built-in also for timeouts

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

3 participants