Skip to content

Commit 433aa21

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

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +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>) => <
27+
export const retryMiddleware = (options: RetryResolvedConfig) => <
2928
Output extends MetadataBearer = MetadataBearer
3029
>(
3130
next: FinalizeHandler<any, Output>,
@@ -49,30 +48,19 @@ export const retryMiddleware = (options: RetryResolvedConfig & Partial<Previousl
4948
request.headers[INVOCATION_ID_HEADER] = v4();
5049
}
5150

52-
let initialSystemClockOffset = 0;
53-
5451
while (true) {
5552
try {
5653
if (isRequest) {
5754
request.headers[REQUEST_HEADER] = `attempt=${attempts + 1}; max=${maxAttempts}`;
5855
}
59-
initialSystemClockOffset = options.systemClockOffset ?? 0 | 0;
6056
const { response, output } = await next(args);
6157
retryStrategy.recordSuccess(retryToken);
6258
output.$metadata.attempts = attempts + 1;
6359
output.$metadata.totalRetryDelay = totalRetryDelay;
6460
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);
61+
} catch (e: any) {
62+
const retryErrorInfo = getRetryErrorInfo(e);
63+
lastError = asSdkError(e);
7664

7765
if (isRequest && isStreamingPayload(request)) {
7866
(context.logger instanceof NoOpLogger ? console : context.logger)?.warn(
@@ -110,7 +98,7 @@ const isRetryStrategyV2 = (retryStrategy: RetryStrategy | RetryStrategyV2) =>
11098
typeof (retryStrategy as RetryStrategyV2).refreshRetryTokenForRetry !== "undefined" &&
11199
typeof (retryStrategy as RetryStrategyV2).recordSuccess !== "undefined";
112100

113-
const getRetryErrorInfo = (error: SkdErrorWithClockSkewMetadata): RetryErrorInfo => {
101+
const getRetryErrorInfo = (error: SdkError): RetryErrorInfo => {
114102
const errorInfo: RetryErrorInfo = {
115103
error,
116104
errorType: getRetryErrorType(error),
@@ -122,7 +110,7 @@ const getRetryErrorInfo = (error: SkdErrorWithClockSkewMetadata): RetryErrorInfo
122110
return errorInfo;
123111
};
124112

125-
const getRetryErrorType = (error: SkdErrorWithClockSkewMetadata): RetryErrorType => {
113+
const getRetryErrorType = (error: SdkError): RetryErrorType => {
126114
if (isThrottlingError(error)) return "THROTTLING";
127115
if (isTransientError(error)) return "TRANSIENT";
128116
if (isServerError(error)) return "SERVER_ERROR";

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ 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+
export const isClockSkewCorrectedError = (error: SdkError) =>
19+
(error as SkdErrorWithClockSkewMetadata).$metadata?.clockSkewCorrected;
20+
1521
export const isThrottlingError = (error: SdkError) =>
1622
error.$metadata?.httpStatusCode === 429 ||
1723
THROTTLING_ERROR_CODES.includes(error.name) ||
@@ -24,7 +30,7 @@ export const isThrottlingError = (error: SdkError) =>
2430
* the name "TimeoutError" to be checked by the TRANSIENT_ERROR_CODES condition.
2531
*/
2632
export const isTransientError = (error: SdkError | SkdErrorWithClockSkewMetadata) =>
27-
(error as SkdErrorWithClockSkewMetadata).$metadata?.clockSkewCorrected ||
33+
isClockSkewCorrectedError(error) ||
2834
TRANSIENT_ERROR_CODES.includes(error.name) ||
2935
NODEJS_TIMEOUT_ERROR_CODES.includes((error as { code?: string })?.code || "") ||
3036
TRANSIENT_ERROR_STATUS_CODES.includes(error.$metadata?.httpStatusCode || 0);

0 commit comments

Comments
 (0)