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 for network errors (e.g. ECONNRESET) #1023

Open
mfulton26 opened this issue Jun 6, 2024 · 6 comments
Open

retries for network errors (e.g. ECONNRESET) #1023

mfulton26 opened this issue Jun 6, 2024 · 6 comments

Comments

@mfulton26
Copy link

mfulton26 commented Jun 6, 2024

sometimes Twilio calls fail for intermittent network/server errors (e.g. ECONNRESET); can the Auto-Retry with Exponential Backoff be updated or a similar option added to also retry under these conditions?

function getExponentialBackoffResponseHandler(
axios: AxiosInstance,
opts: ExponentialBackoffResponseHandlerOptions
) {
const maxIntervalMillis = opts.maxIntervalMillis;
const maxRetries = opts.maxRetries;
return function (res: AxiosResponse<any, any>) {
const config: BackoffAxiosRequestConfig = res.config;
if (res.status !== 429) {
return res;
}
const retryCount = (config.retryCount || 0) + 1;
if (retryCount <= maxRetries) {
config.retryCount = retryCount;
const baseDelay = Math.min(
maxIntervalMillis,
DEFAULT_INITIAL_RETRY_INTERVAL_MILLIS * Math.pow(2, retryCount)
);
const delay = Math.floor(baseDelay * Math.random()); // Full jitter backoff
return new Promise((resolve: (value: Promise<AxiosResponse>) => void) => {
setTimeout(() => resolve(axios(config)), delay);
});
}
return res;
};
}

@adar-h-healthy
Copy link

@tiwarishubham635 Can you please relate to this one? 🙏 We started to get multiple ECONNABORTED errors and this addition can help a lot.

@tiwarishubham635
Copy link
Contributor

We have recently made these changes. I think this will help in your case. This will be available in the coming release

@adar-h-healthy
Copy link

@tiwarishubham635 I might be missing something, but I can't see how this change can help here... It gives the option to change the timeout value, but it doesn't allow to override the retry configuration.

@adar-h-healthy
Copy link

@tiwarishubham635 Would it be ok if we'll open a PR with the change recommended in this issue?

@tiwarishubham635
Copy link
Contributor

Sure, I'll be happy to review it

@adar-h-healthy
Copy link

@tiwarishubham635 I'm having second thoughts about this and you might be able to assist. In some cases when we get the ECONNABORTED error (due to timeout), the request did manage to get to Twilio and the SMS is sent. If we will introduce this retry mechanism, it means that the same request MIGHT be sent twice to Twilio API. I assume that your side supports idempotency, but I wanted to validate this before starting.

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