Skip to content

Commit

Permalink
fix: handle random ENOTFOUND errors
Browse files Browse the repository at this point in the history
closes #441
  • Loading branch information
hmeltaus committed Nov 21, 2023
1 parent b166c14 commit bb4676c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/aws/common/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ const ADDITIONAL_RETRYABLE_ERROR_CODES = [
"TimeoutError",
]

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const decideByLowLevelError = (logger: TkmLogger, error: any): boolean => {
// Fix for random ENOTFOUND errors, see https://github.com/aws/aws-sdk-js-v3/issues/5236
if (
(error.code && error.code === "ENOTFOUND") ||
`${error}`.includes("ENOTFOUND")
) {
logger.warn(`Retry low level nodejs error: ${error}`)
return true
}

return false
}

export const customRetryStrategy = (logger: TkmLogger): RetryStrategy => {
return new StandardRetryStrategy(async () => 30, {
retryDecider: (error) => {
Expand All @@ -28,7 +42,14 @@ export const customRetryStrategy = (logger: TkmLogger): RetryStrategy => {
`Retry decision from additional error codes: ${additionalRetryableErrorCodesDecision}`,
)

return defaultRetryDecision || additionalRetryableErrorCodesDecision
const lowLevelDecision = decideByLowLevelError(logger, error)
logger.trace(`Retry decision from low level error: ${lowLevelDecision}`)

return (
defaultRetryDecision ||
additionalRetryableErrorCodesDecision ||
lowLevelDecision
)
},
delayDecider: (delayBase, attempts) => {
const expBackoff = Math.pow(2, attempts)
Expand Down

0 comments on commit bb4676c

Please sign in to comment.