Skip to content

Commit 0232225

Browse files
committed
move system clock offset check to AWS SDK
1 parent e5c9eeb commit 0232225

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

packages/middleware-retry/src/configurations.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ export interface PreviouslyResolved {
5757
* @internal
5858
*/
5959
retryMode: string | Provider<string>;
60-
61-
systemClockOffset?: number;
6260
}
6361

6462
/**

packages/middleware-retry/src/retryDecider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
} from "@smithy/service-error-classification";
77
import { SdkError } from "@smithy/types";
88

9+
/**
10+
* @deprecated this is only used in the deprecated StandardRetryStrategy. Do not use in new code.
11+
*/
912
export const defaultRetryDecider = (error: SdkError) => {
1013
if (!error) {
1114
return false;

packages/middleware-retry/src/retryMiddleware.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ import {
1616
RetryStrategyV2,
1717
RetryToken,
1818
SdkError,
19-
SkdErrorWithClockSkewMetadata,
2019
} from "@smithy/types";
2120
import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "@smithy/util-retry";
2221
import { v4 } from "uuid";
2322

24-
import { PreviouslyResolved, RetryResolvedConfig } from "./configurations";
23+
import { RetryResolvedConfig } from "./configurations";
2524
import { isStreamingPayload } from "./isStreamingPayload/isStreamingPayload";
2625
import { asSdkError } from "./util";
2726

28-
export const retryMiddleware = (options: RetryResolvedConfig & Partial<PreviouslyResolved>) => <
29-
Output extends MetadataBearer = MetadataBearer
30-
>(
27+
export const retryMiddleware = (options: RetryResolvedConfig) => <Output extends MetadataBearer = MetadataBearer>(
3128
next: FinalizeHandler<any, Output>,
3229
context: HandlerExecutionContext
3330
): FinalizeHandler<any, Output> => async (
@@ -49,30 +46,19 @@ export const retryMiddleware = (options: RetryResolvedConfig & Partial<Previousl
4946
request.headers[INVOCATION_ID_HEADER] = v4();
5047
}
5148

52-
let initialSystemClockOffset = 0;
53-
5449
while (true) {
5550
try {
5651
if (isRequest) {
5752
request.headers[REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`;
5853
}
59-
initialSystemClockOffset = options.systemClockOffset ?? 0 | 0;
6054
const { response, output } = await next(args);
6155
retryStrategy.recordSuccess(retryToken);
6256
output.$metadata.attempts = attempts + 1;
6357
output.$metadata.totalRetryDelay = totalRetryDelay;
6458
return { response, output };
65-
} catch (e: unknown) {
66-
const latestSystemClockOffset = options.systemClockOffset ?? 0 | 0;
67-
const clockSkewCorrected = initialSystemClockOffset !== latestSystemClockOffset;
68-
69-
const sdkError = e as SkdErrorWithClockSkewMetadata;
70-
if (clockSkewCorrected && sdkError.$metadata && typeof sdkError.$metadata === "object") {
71-
sdkError.$metadata.clockSkewCorrected = true;
72-
}
73-
74-
const retryErrorInfo = getRetryErrorInfo(sdkError);
75-
lastError = asSdkError(sdkError);
59+
} catch (e: any) {
60+
const retryErrorInfo = getRetryErrorInfo(e);
61+
lastError = asSdkError(e);
7662

7763
if (isRequest && isStreamingPayload(request)) {
7864
(context.logger instanceof NoOpLogger ? console : context.logger)?.warn(
@@ -110,7 +96,7 @@ const isRetryStrategyV2 = (retryStrategy: RetryStrategy | RetryStrategyV2) =>
11096
typeof (retryStrategy as RetryStrategyV2).refreshRetryTokenForRetry !== "undefined" &&
11197
typeof (retryStrategy as RetryStrategyV2).recordSuccess !== "undefined";
11298

113-
const getRetryErrorInfo = (error: SkdErrorWithClockSkewMetadata): RetryErrorInfo => {
99+
const getRetryErrorInfo = (error: SdkError): RetryErrorInfo => {
114100
const errorInfo: RetryErrorInfo = {
115101
error,
116102
errorType: getRetryErrorType(error),
@@ -122,7 +108,7 @@ const getRetryErrorInfo = (error: SkdErrorWithClockSkewMetadata): RetryErrorInfo
122108
return errorInfo;
123109
};
124110

125-
const getRetryErrorType = (error: SkdErrorWithClockSkewMetadata): RetryErrorType => {
111+
const getRetryErrorType = (error: SdkError): RetryErrorType => {
126112
if (isThrottlingError(error)) return "THROTTLING";
127113
if (isTransientError(error)) return "TRANSIENT";
128114
if (isServerError(error)) return "SERVER_ERROR";

packages/service-error-classification/src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ import {
1010

1111
export const isRetryableByTrait = (error: SdkError) => error.$retryable !== undefined;
1212

13+
/**
14+
* @deprecated use isClockSkewCorrectedError. This is only used in deprecated code.
15+
*/
1316
export const isClockSkewError = (error: SdkError) => CLOCK_SKEW_ERROR_CODES.includes(error.name);
1417

18+
/**
19+
* @returns whether the error resulted in a systemClockOffset aka clock skew correction.
20+
*/
21+
export const isClockSkewCorrectedError = (error: SdkError) =>
22+
(error as SkdErrorWithClockSkewMetadata).$metadata?.clockSkewCorrected;
23+
1524
export const isThrottlingError = (error: SdkError) =>
1625
error.$metadata?.httpStatusCode === 429 ||
1726
THROTTLING_ERROR_CODES.includes(error.name) ||
@@ -24,7 +33,7 @@ export const isThrottlingError = (error: SdkError) =>
2433
* the name "TimeoutError" to be checked by the TRANSIENT_ERROR_CODES condition.
2534
*/
2635
export const isTransientError = (error: SdkError | SkdErrorWithClockSkewMetadata) =>
27-
(error as SkdErrorWithClockSkewMetadata).$metadata?.clockSkewCorrected ||
36+
isClockSkewCorrectedError(error) ||
2837
TRANSIENT_ERROR_CODES.includes(error.name) ||
2938
NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") ||
3039
TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0);

0 commit comments

Comments
 (0)