From 95ff6cfd0fab17a657bc35a211d15af40bca8e36 Mon Sep 17 00:00:00 2001 From: Nazar Leush Date: Tue, 2 Jul 2024 22:09:04 +0300 Subject: [PATCH] update algorythm --- lib/fetch.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/fetch.js b/lib/fetch.js index e511d70f4..aff91d0ed 100644 --- a/lib/fetch.js +++ b/lib/fetch.js @@ -28,18 +28,12 @@ const fetchH1 = h1NoCache({ rejectUnauthorized: false // By default skip auth check for all. }).fetch; -const RETRY_ON_ERROR = [ - 'ECONNRESET', +const ERRORS_TO_RETRY = [ + 'ECONN', 'EAI_AGAIN', - 'ECONNREFUSED', - 'ENETUNREACH', - 'HPE_INVALID_HEADER_TOKEN', - 'HPE_INVALID_CONSTANT', - 'ERR_SSL_SSLV3_ALERT_HANDSHAKE_FAILURE', - 'ERR_SSL_UNSUPPORTED_PROTOCOL', - 'ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR', - 'ERR_SSL_UNSAFE_LEGACY_REGENERATION_DISABLED', - 'ERR_SSL_WRONG_VERSION_NUMBER' + 'ENET', + 'HPE_INVALID_', + 'ERR_SSL_' ]; function doFetch(fetch_func, h1_fetch_func, options) { @@ -104,10 +98,10 @@ function doFetch(fetch_func, h1_fetch_func, options) { log(' -- doFetch h2 aborted error', uri); resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {disable_http2: true}))); - } else if (!options.retry_onerror && RETRY_ON_ERROR.indexOf(error.code) > -1) { + } else if (!options.stopRecursion && ERRORS_TO_RETRY.some(code => code.indexOf(error.code) > -1)) { log(' -- doFetch ECONNRESET retry', error.code, uri); - resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {retry_onerror: true, disable_http2: true}))); + resolve(doFetch(fetch_func, h1_fetch_func, Object.assign({}, options, {stopRecursion: true, disable_http2: true}))); } else { if (error instanceof AbortError) {