From ab0e7be36e7e7f8a0c04834357aaad643c7912c3 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 5 Oct 2022 14:00:12 -0400 Subject: [PATCH] fix(node-http-handler): check for error code in isTransientError (#4018) --- packages/node-http-handler/src/constants.ts | 1 + packages/service-error-classification/src/constants.ts | 5 +++++ packages/service-error-classification/src/index.ts | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/packages/node-http-handler/src/constants.ts b/packages/node-http-handler/src/constants.ts index 50c53e68c301..627b84faccb8 100644 --- a/packages/node-http-handler/src/constants.ts +++ b/packages/node-http-handler/src/constants.ts @@ -1,4 +1,5 @@ /** * Node.js system error codes that indicate timeout. + * @deprecated use NODEJS_TIMEOUT_ERROR_CODES from @aws-sdk/service-error-classification/constants */ export const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"]; diff --git a/packages/service-error-classification/src/constants.ts b/packages/service-error-classification/src/constants.ts index d5ce4ec84762..61f6f2f08cab 100644 --- a/packages/service-error-classification/src/constants.ts +++ b/packages/service-error-classification/src/constants.ts @@ -45,3 +45,8 @@ export const TRANSIENT_ERROR_CODES = ["AbortError", "TimeoutError", "RequestTime * Error codes that indicate transient issues */ export const TRANSIENT_ERROR_STATUS_CODES = [500, 502, 503, 504]; + +/** + * Node.js system error codes that indicate timeout. + */ +export const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "EPIPE", "ETIMEDOUT"]; diff --git a/packages/service-error-classification/src/index.ts b/packages/service-error-classification/src/index.ts index ade8560211dc..efc0054e3d3b 100644 --- a/packages/service-error-classification/src/index.ts +++ b/packages/service-error-classification/src/index.ts @@ -2,6 +2,7 @@ import { SdkError } from "@aws-sdk/types"; import { CLOCK_SKEW_ERROR_CODES, + NODEJS_TIMEOUT_ERROR_CODES, THROTTLING_ERROR_CODES, TRANSIENT_ERROR_CODES, TRANSIENT_ERROR_STATUS_CODES, @@ -16,6 +17,13 @@ export const isThrottlingError = (error: SdkError) => THROTTLING_ERROR_CODES.includes(error.name) || error.$retryable?.throttling == true; +/** + * Though NODEJS_TIMEOUT_ERROR_CODES are platform specific, they are + * included here because there is an error scenario with unknown root + * cause where the NodeHttpHandler does not decorate the Error with + * the name "TimeoutError" to be checked by the TRANSIENT_ERROR_CODES condition. + */ export const isTransientError = (error: SdkError) => TRANSIENT_ERROR_CODES.includes(error.name) || + NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") || TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0);