Skip to content

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

@mfulton26

Description

@mfulton26

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;
};
}

Metadata

Metadata

Assignees

Labels

TwiDi-InProgressIssue is being actively worked on by TwiDIpriority: mediumImportant but not urgent; Workaround availabletype: bugbug in the library

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions