From 68e514ec377321c41f69bed6ef9b4dd96900796c Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Sat, 6 Aug 2022 12:46:53 +0530 Subject: [PATCH 1/2] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2ba1e24..fe9b632 100644 --- a/index.js +++ b/index.js @@ -208,7 +208,7 @@ module.exports = async function (url, options) { const waitTime = getRetryDelay(retryOptions); let timeoutHandler; - if (retryOptions.socketTimeout) { + if (!options.signal && retryOptions.socketTimeout) { const controller = new AbortController(); timeoutHandler = setTimeout(() => controller.abort(), retryOptions.socketTimeout); options.signal = controller.signal; From 001b7f1afa86a9ab99b2248fabc90f15ee0c7392 Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Sat, 6 Aug 2022 13:12:22 +0530 Subject: [PATCH 2/2] Update index.js --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index fe9b632..b2e21fd 100644 --- a/index.js +++ b/index.js @@ -99,7 +99,7 @@ function retryInit(options={}) { retryOnHttpResponse: ((typeof retryOptions.retryOnHttpResponse === 'function') && retryOptions.retryOnHttpResponse) || ((response) => { return response.status >= 500; }), retryOnHttpError: ((typeof retryOptions.retryOnHttpError === 'function') && retryOptions.retryOnHttpError) || - ((error) => { return shouldRetryOnHttpError(error); }), + ((error) => { return shouldRetryOnHttpError(error, !!options.signal); }), socketTimeout: socketTimeoutValue }; } @@ -150,14 +150,14 @@ function checkParameters(retryOptions) { * @param {Object} error * @returns Returns true for all FetchError's of type `system` */ -function shouldRetryOnHttpError(error) { +function shouldRetryOnHttpError(error, ignoreAborted) { // special handling for known fetch errors: https://github.com/node-fetch/node-fetch/blob/main/docs/ERROR-HANDLING.md // retry on all errors originating from Node.js core // retry on AbortError caused by network timeouts if (error.name === 'FetchError' && error.type === 'system') { console.error(`FetchError failed with code: ${error.code}; message: ${error.message}`); return true; - } else if (error.name === 'AbortError') { + } else if (error.name === 'AbortError' && !ignoreAborted) { console.error(`AbortError failed with type: ${error.type}; message: ${error.message}`); return true; } @@ -212,7 +212,7 @@ module.exports = async function (url, options) { const controller = new AbortController(); timeoutHandler = setTimeout(() => controller.abort(), retryOptions.socketTimeout); options.signal = controller.signal; - } + } try { const response = await fetch(url, options);