Skip to content

Commit

Permalink
fetch: retry on ECONNRESET
Browse files Browse the repository at this point in the history
  • Loading branch information
nleush committed Jul 1, 2024
1 parent 17c8cdb commit f99d5f1
Showing 1 changed file with 21 additions and 14 deletions.
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.retry_onerror && error.code === 'ECONNRESET') {

log(' -- doFetch ECONNRESET retry', error.code, uri);
resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {retry_onerror: 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 f99d5f1

Please sign in to comment.