From 6fa39b3ee29530f292f167aceb10fb1e357b9116 Mon Sep 17 00:00:00 2001 From: siosonel Date: Tue, 10 Dec 2024 16:19:23 -0600 Subject: [PATCH] do not use console.warn() in mayRetryDsPreInit(); support more recoverable error codes --- server/src/mds3.preInit.ts | 4 ++-- server/src/utils.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server/src/mds3.preInit.ts b/server/src/mds3.preInit.ts index 95504f25b8..f18d1c25d7 100644 --- a/server/src/mds3.preInit.ts +++ b/server/src/mds3.preInit.ts @@ -37,7 +37,7 @@ export async function mayRetryDsPreInit(ds: Mds3): Promise { throw new Error('preInit error: ' + (response.message || response)) } else { // ok to retry on recoverable error - console.warn(`First ${ds.label} preInit.getStatus() request failed. (${retryMax} attempts left)`) + console.log(`First ${ds.label} preInit.getStatus() request failed. (${retryMax} attempts left)`) // subsequent retries uses a loop via setInterval // NOTE: Using await with recursive function may have memory performance penalties, // since a new promise gets created with each recursion and its not clear how @@ -59,7 +59,7 @@ export async function mayRetryDsPreInit(ds: Mds3): Promise { } } catch (response) { //console.log(89, response) - console.warn(`preInit.getStatus() check failed. Retrying... (${retryMax - currentRetry} attempts left)`) + console.log(`preInit.getStatus() check failed. Retrying... (${retryMax - currentRetry} attempts left)`) if (currentRetry >= retryMax) { clearInterval(interval) // cancel retries console.error('Max preInit.getStatus() retry attempts reached. Failing with error:', response) diff --git a/server/src/utils.js b/server/src/utils.js index e5a50b9d4c..cf8cdf9c9a 100644 --- a/server/src/utils.js +++ b/server/src/utils.js @@ -794,6 +794,18 @@ export function boxplot_getvalue(lst) { return { w1, w2, p05, p25, p50, p75, p95, iqr, out } } +const RecoverableErrorCodes = new Set([ + 'ECONNRESET', + 'ECONNREFUSED', + 'ENOTFOUND', + 'ENETDOWN', + 'ENETUNREACH', + 'EHOSTDOWN', + 'EHOSTUNREACH', + 'EPIPE', + 'UND_ERR_SOCKET' +]) + // only use this helper when catching errors that may be due to // external API server errors or network connection failures; // the `e` argument is expected to have a network-related error code, some of which @@ -811,7 +823,7 @@ export function isRecoverableError(e) { // code=ENOTFOUND, ETIMEDOUT, etc below are from undici when network is down, // it's not an HTTP response status code from an API if (e.cause?.errors) console.log(e.cause.code, e.cause.errors) - return code == 'ENOTFOUND' || code == 'ETIMEDOUT' + return RecoverableErrorCodes.has(code) } const extApiCache = serverconfig.features?.extApiCache || {}