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

Feature: retry econnreset #544

Merged
merged 7 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,15 @@
"twitter.status": {}
},

LOG_DATE_FORMAT: "\\[YY-MM-DD HH:mm:ss\\]:"
LOG_DATE_FORMAT: "\\[YY-MM-DD HH:mm:ss\\]:",

ERRORS_TO_RETRY: [
'ECONN',
'EAI_AGAIN',
'ENET',
'HPE_INVALID_',
'ERR_SSL_'
]
};

// Providers config loader.
Expand Down
35 changes: 21 additions & 14 deletions lib/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,31 @@ function doFetch(fetch_func, h1_fetch_func, options) {
.catch(error => {
clearTimeout(timeoutTimerId);
if (!options.disable_http2 && error.code && /^ERR_HTTP2/.test(error.code)) {

log(' -- doFetch http2 error', error.code, uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true})));

} else if (!options.disable_http2 && error.code && error instanceof FetchError && error.code === 'ABORT_ERR') {

// Special case, when shared session request aborted by htmlparser logic.
/**
* https://polldaddy.com/poll/7451882/?s=twitter
* https://app.everviz.com/show/O0Cy7Dyt
*/
log(' -- doFetch h2 aborted error', uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true})));

} else if (!options.stopRecursion && CONFIG.ERRORS_TO_RETRY?.some(code => error.code?.indexOf(code) > -1)) {

log(' -- doFetch ECONNRESET retry', error.code, uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {stopRecursion: true, disable_http2: true})));

} else {
if (!options.disable_http2 && error.code && error instanceof FetchError && error.code === 'ABORT_ERR') {
// Special case, when shared session request aborted by htmlparser logic.
/**
* https://polldaddy.com/poll/7451882/?s=twitter
* https://app.everviz.com/show/O0Cy7Dyt
*/
log(' -- doFetch h2 aborted error', uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true})));
} else {
if (error instanceof AbortError) {
// `AbortError` before `response` occurs only on timeout.
error = 'timeout';
}
reject(error);
if (error instanceof AbortError) {
// `AbortError` before `response` occurs only on timeout.
error = 'timeout';
}
reject(error);
}
});
});
Expand Down