Skip to content

Commit

Permalink
do not use console.warn() in mayRetryDsPreInit(); support more recove…
Browse files Browse the repository at this point in the history
…rable error codes
  • Loading branch information
siosonel committed Dec 10, 2024
1 parent a443653 commit 6fa39b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions server/src/mds3.preInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function mayRetryDsPreInit(ds: Mds3): Promise<any> {
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
Expand All @@ -59,7 +59,7 @@ export async function mayRetryDsPreInit(ds: Mds3): Promise<any> {
}
} 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)
Expand Down
14 changes: 13 additions & 1 deletion server/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 || {}
Expand Down

0 comments on commit 6fa39b3

Please sign in to comment.