Skip to content

Commit

Permalink
Feature: retry econnreset (#544)
Browse files Browse the repository at this point in the history
* fetch: retry on ECONNRESET

* retry on errors list

* update algorythm

* bugfix

* bugfix undefined

* CONFIG.ERRORS_TO_RETRY

* allow ERRORS_TO_RETRY == null
  • Loading branch information
nleush authored Jul 2, 2024
1 parent 17c8cdb commit c036338
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
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

0 comments on commit c036338

Please sign in to comment.