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 · 0 comments
Open

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

mfulton26 opened this issue Jun 6, 2024 · 0 comments

Comments

@mfulton26
Copy link

sometimes Twilio calls fails 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;
};
}

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

1 participant