@cdk8s/awscdk-resolver 0.0.725 → 0.0.727

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.jsii +3 -3
  2. package/lib/resolve.js +1 -1
  3. package/node_modules/@aws-sdk/client-cloudformation/dist-cjs/index.js +3 -2
  4. package/node_modules/@aws-sdk/client-cloudformation/dist-es/runtimeConfig.js +2 -1
  5. package/node_modules/@aws-sdk/client-cloudformation/dist-types/runtimeConfig.d.ts +1 -0
  6. package/node_modules/@aws-sdk/client-cloudformation/dist-types/ts3.4/runtimeConfig.d.ts +1 -0
  7. package/node_modules/@aws-sdk/client-cloudformation/package.json +3 -3
  8. package/node_modules/@aws-sdk/core/dist-cjs/submodules/client/index.js +12 -0
  9. package/node_modules/@aws-sdk/core/dist-es/submodules/client/getDefaultSocketTimeout.js +10 -0
  10. package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.browser.js +1 -0
  11. package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.js +1 -0
  12. package/node_modules/@aws-sdk/core/dist-es/submodules/client/index.native.js +1 -0
  13. package/node_modules/@aws-sdk/core/dist-types/submodules/client/getDefaultSocketTimeout.d.ts +11 -0
  14. package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.browser.d.ts +1 -0
  15. package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.d.ts +1 -0
  16. package/node_modules/@aws-sdk/core/dist-types/submodules/client/index.native.d.ts +1 -0
  17. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/getDefaultSocketTimeout.d.ts +4 -0
  18. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.browser.d.ts +1 -0
  19. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.d.ts +1 -0
  20. package/node_modules/@aws-sdk/core/dist-types/ts3.4/submodules/client/index.native.d.ts +1 -0
  21. package/node_modules/@aws-sdk/core/package.json +1 -1
  22. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  23. package/node_modules/@aws-sdk/credential-provider-http/package.json +2 -2
  24. package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
  25. package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
  26. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  27. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  28. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  29. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  30. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +3 -2
  31. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +3 -2
  32. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +3 -2
  33. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +3 -2
  34. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +3 -2
  35. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/cognito-identity/runtimeConfig.js +2 -1
  36. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/signin/runtimeConfig.js +2 -1
  37. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso/runtimeConfig.js +2 -1
  38. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sso-oidc/runtimeConfig.js +2 -1
  39. package/node_modules/@aws-sdk/nested-clients/dist-es/submodules/sts/runtimeConfig.js +2 -1
  40. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/cognito-identity/runtimeConfig.d.ts +1 -0
  41. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/signin/runtimeConfig.d.ts +1 -0
  42. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sso/runtimeConfig.d.ts +1 -0
  43. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sso-oidc/runtimeConfig.d.ts +1 -0
  44. package/node_modules/@aws-sdk/nested-clients/dist-types/submodules/sts/runtimeConfig.d.ts +1 -0
  45. package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/cognito-identity/runtimeConfig.d.ts +1 -0
  46. package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/signin/runtimeConfig.d.ts +1 -0
  47. package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/sso/runtimeConfig.d.ts +1 -0
  48. package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/sso-oidc/runtimeConfig.d.ts +1 -0
  49. package/node_modules/@aws-sdk/nested-clients/dist-types/ts3.4/submodules/sts/runtimeConfig.d.ts +1 -0
  50. package/node_modules/@aws-sdk/nested-clients/package.json +2 -2
  51. package/node_modules/@aws-sdk/token-providers/package.json +3 -3
  52. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +1 -0
  53. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.browser.js +33 -5
  54. package/node_modules/@smithy/core/dist-cjs/submodules/retry/index.js +33 -5
  55. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/command.js +1 -0
  56. package/node_modules/@smithy/core/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +11 -5
  57. package/node_modules/@smithy/core/dist-es/submodules/retry/util-retry/race.js +22 -0
  58. package/node_modules/@smithy/core/dist-types/submodules/retry/util-retry/race.d.ts +3 -0
  59. package/node_modules/@smithy/core/dist-types/ts3.4/submodules/retry/util-retry/race.d.ts +3 -0
  60. package/node_modules/@smithy/core/package.json +2 -2
  61. package/node_modules/@smithy/fetch-http-handler/dist-cjs/index.js +10 -4
  62. package/node_modules/@smithy/fetch-http-handler/dist-es/fetch-http-handler.js +6 -2
  63. package/node_modules/@smithy/fetch-http-handler/dist-es/request-timeout.js +4 -2
  64. package/node_modules/@smithy/fetch-http-handler/dist-types/request-timeout.d.ts +12 -1
  65. package/node_modules/@smithy/fetch-http-handler/dist-types/ts3.4/request-timeout.d.ts +12 -1
  66. package/node_modules/@smithy/fetch-http-handler/package.json +3 -3
  67. package/node_modules/@smithy/node-http-handler/dist-cjs/index.js +31 -31
  68. package/node_modules/@smithy/node-http-handler/dist-es/node-http-handler.js +2 -4
  69. package/node_modules/@smithy/node-http-handler/dist-es/set-socket-timeout.js +29 -27
  70. package/node_modules/@smithy/node-http-handler/dist-types/set-socket-timeout.d.ts +7 -3
  71. package/node_modules/@smithy/node-http-handler/dist-types/ts3.4/set-socket-timeout.d.ts +7 -3
  72. package/node_modules/@smithy/node-http-handler/package.json +3 -3
  73. package/node_modules/@smithy/types/dist-types/middleware.d.ts +6 -0
  74. package/node_modules/@smithy/types/dist-types/ts3.4/middleware.d.ts +6 -0
  75. package/node_modules/@smithy/types/package.json +1 -1
  76. package/package.json +6 -6
@@ -1,5 +1,5 @@
1
1
  import packageInfo from "../../../package.json";
2
- import { createDefaultUserAgentProvider, emitWarningIfUnsupportedVersion as awsCheckVersion, NODE_APP_ID_CONFIG_OPTIONS, } from "@aws-sdk/core/client";
2
+ import { createDefaultUserAgentProvider, emitWarningIfUnsupportedVersion as awsCheckVersion, getDefaultSocketTimeout, NODE_APP_ID_CONFIG_OPTIONS, } from "@aws-sdk/core/client";
3
3
  import { NODE_AUTH_SCHEME_PREFERENCE_OPTIONS } from "@aws-sdk/core/httpAuthSchemes";
4
4
  import { emitWarningIfUnsupportedVersion, loadConfigsForDefaultMode } from "@smithy/core/client";
5
5
  import { loadConfig as loadNodeConfig, NODE_REGION_CONFIG_FILE_OPTIONS, NODE_REGION_CONFIG_OPTIONS, NODE_USE_DUALSTACK_ENDPOINT_CONFIG_OPTIONS, NODE_USE_FIPS_ENDPOINT_CONFIG_OPTIONS, resolveDefaultsModeConfig, } from "@smithy/core/config";
@@ -24,6 +24,7 @@ export const getRuntimeConfig = (config) => {
24
24
  defaultsMode,
25
25
  authSchemePreference: config?.authSchemePreference ?? loadNodeConfig(NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, loaderConfig),
26
26
  bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
27
+ defaultSocketTimeout: getDefaultSocketTimeout(config?.requestHandler, 300_000),
27
28
  defaultUserAgentProvider: config?.defaultUserAgentProvider ?? createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
28
29
  maxAttempts: config?.maxAttempts ?? loadNodeConfig(NODE_MAX_ATTEMPT_CONFIG_OPTIONS, config),
29
30
  region: config?.region ?? loadNodeConfig(NODE_REGION_CONFIG_OPTIONS, { ...NODE_REGION_CONFIG_FILE_OPTIONS, ...loaderConfig }),
@@ -1,5 +1,5 @@
1
1
  import packageInfo from "../../../package.json";
2
- import { createDefaultUserAgentProvider, emitWarningIfUnsupportedVersion as awsCheckVersion, NODE_APP_ID_CONFIG_OPTIONS, } from "@aws-sdk/core/client";
2
+ import { createDefaultUserAgentProvider, emitWarningIfUnsupportedVersion as awsCheckVersion, getDefaultSocketTimeout, NODE_APP_ID_CONFIG_OPTIONS, } from "@aws-sdk/core/client";
3
3
  import { AwsSdkSigV4ASigner, AwsSdkSigV4Signer, NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, NODE_SIGV4A_CONFIG_OPTIONS, } from "@aws-sdk/core/httpAuthSchemes";
4
4
  import { NoAuthSigner } from "@smithy/core";
5
5
  import { emitWarningIfUnsupportedVersion, loadConfigsForDefaultMode } from "@smithy/core/client";
@@ -25,6 +25,7 @@ export const getRuntimeConfig = (config) => {
25
25
  defaultsMode,
26
26
  authSchemePreference: config?.authSchemePreference ?? loadNodeConfig(NODE_AUTH_SCHEME_PREFERENCE_OPTIONS, loaderConfig),
27
27
  bodyLengthChecker: config?.bodyLengthChecker ?? calculateBodyLength,
28
+ defaultSocketTimeout: getDefaultSocketTimeout(config?.requestHandler, 300_000),
28
29
  defaultUserAgentProvider: config?.defaultUserAgentProvider ?? createDefaultUserAgentProvider({ serviceId: clientSharedValues.serviceId, clientVersion: packageInfo.version }),
29
30
  httpAuthSchemes: config?.httpAuthSchemes ?? [
30
31
  {
@@ -51,6 +51,7 @@ export declare const getRuntimeConfig: (config: CognitoIdentityClientConfig) =>
51
51
  defaultsMode: import("@smithy/types").Provider<import("@smithy/core/client").ResolvedDefaultsMode>;
52
52
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
53
53
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
54
+ defaultSocketTimeout: number | undefined;
54
55
  defaultUserAgentProvider: (config?: import("@aws-sdk/core/client").PreviouslyResolved) => Promise<import("@smithy/types").UserAgent>;
55
56
  maxAttempts: number | import("@smithy/types").Provider<number>;
56
57
  region: string | import("@smithy/types").Provider<string>;
@@ -51,6 +51,7 @@ export declare const getRuntimeConfig: (config: SigninClientConfig) => {
51
51
  defaultsMode: import("@smithy/types").Provider<import("@smithy/core/client").ResolvedDefaultsMode>;
52
52
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
53
53
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
54
+ defaultSocketTimeout: number | undefined;
54
55
  defaultUserAgentProvider: (config?: import("@aws-sdk/core/client").PreviouslyResolved) => Promise<import("@smithy/types").UserAgent>;
55
56
  maxAttempts: number | import("@smithy/types").Provider<number>;
56
57
  region: string | import("@smithy/types").Provider<string>;
@@ -51,6 +51,7 @@ export declare const getRuntimeConfig: (config: SSOClientConfig) => {
51
51
  defaultsMode: import("@smithy/types").Provider<import("@smithy/core/client").ResolvedDefaultsMode>;
52
52
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
53
53
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
54
+ defaultSocketTimeout: number | undefined;
54
55
  defaultUserAgentProvider: (config?: import("@aws-sdk/core/client").PreviouslyResolved) => Promise<import("@smithy/types").UserAgent>;
55
56
  maxAttempts: number | import("@smithy/types").Provider<number>;
56
57
  region: string | import("@smithy/types").Provider<string>;
@@ -51,6 +51,7 @@ export declare const getRuntimeConfig: (config: SSOOIDCClientConfig) => {
51
51
  defaultsMode: import("@smithy/types").Provider<import("@smithy/core/client").ResolvedDefaultsMode>;
52
52
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
53
53
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
54
+ defaultSocketTimeout: number | undefined;
54
55
  defaultUserAgentProvider: (config?: import("@aws-sdk/core/client").PreviouslyResolved) => Promise<import("@smithy/types").UserAgent>;
55
56
  maxAttempts: number | import("@smithy/types").Provider<number>;
56
57
  region: string | import("@smithy/types").Provider<string>;
@@ -46,6 +46,7 @@ export declare const getRuntimeConfig: (config: STSClientConfig) => {
46
46
  defaultsMode: import("@smithy/types").Provider<import("@smithy/core/client").ResolvedDefaultsMode>;
47
47
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
48
48
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
49
+ defaultSocketTimeout: number | undefined;
49
50
  defaultUserAgentProvider: (config?: import("@aws-sdk/core/client").PreviouslyResolved) => Promise<import("@smithy/types").UserAgent>;
50
51
  httpAuthSchemes: import("@smithy/types").HttpAuthScheme[] | ({
51
52
  schemeId: string;
@@ -94,6 +94,7 @@ export declare const getRuntimeConfig: (config: CognitoIdentityClientConfig) =>
94
94
  >;
95
95
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
96
96
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
97
+ defaultSocketTimeout: number | undefined;
97
98
  defaultUserAgentProvider: (
98
99
  config?: import("@aws-sdk/core/client").PreviouslyResolved,
99
100
  ) => Promise<import("@smithy/types").UserAgent>;
@@ -94,6 +94,7 @@ export declare const getRuntimeConfig: (config: SigninClientConfig) => {
94
94
  >;
95
95
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
96
96
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
97
+ defaultSocketTimeout: number | undefined;
97
98
  defaultUserAgentProvider: (
98
99
  config?: import("@aws-sdk/core/client").PreviouslyResolved,
99
100
  ) => Promise<import("@smithy/types").UserAgent>;
@@ -94,6 +94,7 @@ export declare const getRuntimeConfig: (config: SSOClientConfig) => {
94
94
  >;
95
95
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
96
96
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
97
+ defaultSocketTimeout: number | undefined;
97
98
  defaultUserAgentProvider: (
98
99
  config?: import("@aws-sdk/core/client").PreviouslyResolved,
99
100
  ) => Promise<import("@smithy/types").UserAgent>;
@@ -94,6 +94,7 @@ export declare const getRuntimeConfig: (config: SSOOIDCClientConfig) => {
94
94
  >;
95
95
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
96
96
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
97
+ defaultSocketTimeout: number | undefined;
97
98
  defaultUserAgentProvider: (
98
99
  config?: import("@aws-sdk/core/client").PreviouslyResolved,
99
100
  ) => Promise<import("@smithy/types").UserAgent>;
@@ -78,6 +78,7 @@ export declare const getRuntimeConfig: (config: STSClientConfig) => {
78
78
  >;
79
79
  authSchemePreference: string[] | import("@smithy/types").Provider<string[]>;
80
80
  bodyLengthChecker: import("@smithy/types").BodyLengthCalculator;
81
+ defaultSocketTimeout: number | undefined;
81
82
  defaultUserAgentProvider: (
82
83
  config?: import("@aws-sdk/core/client").PreviouslyResolved,
83
84
  ) => Promise<import("@smithy/types").UserAgent>;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/nested-clients",
3
- "version": "3.997.54",
3
+ "version": "3.998.0",
4
4
  "description": "Nested clients for AWS SDK packages.",
5
5
  "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/nested-clients",
6
6
  "license": "Apache-2.0",
@@ -100,7 +100,7 @@
100
100
  "test:watch": "yarn g:vitest watch"
101
101
  },
102
102
  "dependencies": {
103
- "@aws-sdk/core": "^3.979.1",
103
+ "@aws-sdk/core": "^3.980.0",
104
104
  "@aws-sdk/signature-v4-multi-region": "^3.996.51",
105
105
  "@aws-sdk/types": "^3.975.0",
106
106
  "@smithy/core": "^3.38.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/token-providers",
3
- "version": "3.1161.0",
3
+ "version": "3.1162.0",
4
4
  "description": "A collection of token providers",
5
5
  "keywords": [
6
6
  "aws",
@@ -48,8 +48,8 @@
48
48
  "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
49
49
  },
50
50
  "dependencies": {
51
- "@aws-sdk/core": "^3.979.1",
52
- "@aws-sdk/nested-clients": "^3.997.54",
51
+ "@aws-sdk/core": "^3.980.0",
52
+ "@aws-sdk/nested-clients": "^3.998.0",
53
53
  "@aws-sdk/types": "^3.975.0",
54
54
  "@smithy/core": "^3.38.0",
55
55
  "@smithy/types": "^4.19.0",
@@ -615,6 +615,7 @@ class Command {
615
615
  commandInstance: this,
616
616
  ...smithyContext,
617
617
  ...(options?.metricsRecorder === undefined ? {} : { metricsRecorder: options.metricsRecorder }),
618
+ ...(options?.abortSignal === undefined ? {} : { abortSignal: options.abortSignal }),
618
619
  },
619
620
  };
620
621
  const { requestHandler } = configuration;
@@ -1,6 +1,7 @@
1
1
  const { NoOpLogger, normalizeProvider } = require("@smithy/core/client");
2
2
  const { HttpResponse, HttpRequest } = require("@smithy/core/protocols");
3
3
  const { parseRfc7231DateTime, v4 } = require("@smithy/core/serde");
4
+ const { SMITHY_CONTEXT_KEY } = require("@smithy/types");
4
5
  const { hasOwn } = require("@smithy/core/transport");
5
6
 
6
7
  const isStreamingPayload = (request) => request?.body instanceof ReadableStream;
@@ -80,6 +81,29 @@ function isNodeJsHttp2TransientError(error) {
80
81
  return error.code === "ERR_HTTP2_STREAM_ERROR" && error.message.includes("NGHTTP2_REFUSED_STREAM");
81
82
  }
82
83
 
84
+ const race = (promise, signal) => {
85
+ if (!signal) {
86
+ return promise;
87
+ }
88
+ let cleanup = () => { };
89
+ const aborted = new Promise((_, reject) => {
90
+ const handler = () => reject(createAbortError());
91
+ if (signal.aborted) {
92
+ handler();
93
+ }
94
+ else if (typeof signal.addEventListener === "function") {
95
+ signal.addEventListener("abort", handler, { once: true });
96
+ cleanup = () => signal.removeEventListener("abort", handler);
97
+ }
98
+ else {
99
+ signal.onabort = handler;
100
+ }
101
+ });
102
+ return Promise.race([promise, aborted]).finally(cleanup);
103
+ };
104
+ const createAbortError = () => Object.assign(new Error("Request aborted"), { name: "AbortError" });
105
+ const isAbortError = (error) => typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
106
+
83
107
  const DEFAULT_RETRY_DELAY_BASE = 100;
84
108
  const MAXIMUM_RETRY_DELAY = 20 * 1000;
85
109
  const THROTTLING_RETRY_DELAY_BASE = 500;
@@ -158,9 +182,11 @@ function bindRetryMiddleware(isStreamingPayload) {
158
182
  return (options) => (next, context) => async (args) => {
159
183
  let retryStrategy = await options.retryStrategy();
160
184
  const maxAttempts = await options.maxAttempts();
185
+ const abortSignal = context[SMITHY_CONTEXT_KEY]?.abortSignal;
161
186
  if (isRetryStrategyV2(retryStrategy)) {
162
187
  retryStrategy = retryStrategy;
163
- let retryToken = await retryStrategy.acquireInitialRetryToken((context["partition_id"] ?? "") + (context.__retryLongPoll ? ":longpoll" : ""));
188
+ const retryTokenScope = (context["partition_id"] ?? "") + (context.__retryLongPoll ? ":longpoll" : "");
189
+ let retryToken = await race(retryStrategy.acquireInitialRetryToken(retryTokenScope), abortSignal);
164
190
  let lastError = new Error();
165
191
  let attempts = 0;
166
192
  let totalRetryDelay = 0;
@@ -188,9 +214,12 @@ function bindRetryMiddleware(isStreamingPayload) {
188
214
  throw lastError;
189
215
  }
190
216
  try {
191
- retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo);
217
+ retryToken = await race(retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo), abortSignal);
192
218
  }
193
- catch (ignoredRefreshError) {
219
+ catch (refreshError) {
220
+ if (abortSignal?.aborted && isAbortError(refreshError)) {
221
+ throw refreshError;
222
+ }
194
223
  if (!lastError.$metadata) {
195
224
  lastError.$metadata = {};
196
225
  }
@@ -202,7 +231,7 @@ function bindRetryMiddleware(isStreamingPayload) {
202
231
  const delay = retryToken.getRetryDelay();
203
232
  totalRetryDelay += (retryToken?.$retryLog?.acquisitionDelay ?? 0) + delay;
204
233
  if (delay > 0) {
205
- await cooldown(delay);
234
+ await race(new Promise((resolve) => setTimeout(resolve, delay)), abortSignal);
206
235
  }
207
236
  }
208
237
  }
@@ -216,7 +245,6 @@ function bindRetryMiddleware(isStreamingPayload) {
216
245
  }
217
246
  };
218
247
  }
219
- const cooldown = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
220
248
  const isRetryStrategyV2 = (retryStrategy) => typeof retryStrategy.acquireInitialRetryToken !== "undefined" &&
221
249
  typeof retryStrategy.refreshRetryTokenForRetry !== "undefined" &&
222
250
  typeof retryStrategy.recordSuccess !== "undefined";
@@ -2,6 +2,7 @@ const { Readable } = require("node:stream");
2
2
  const { NoOpLogger, normalizeProvider } = require("@smithy/core/client");
3
3
  const { HttpResponse, HttpRequest } = require("@smithy/core/protocols");
4
4
  const { parseRfc7231DateTime, v4 } = require("@smithy/core/serde");
5
+ const { SMITHY_CONTEXT_KEY } = require("@smithy/types");
5
6
  const { hasOwn } = require("@smithy/core/transport");
6
7
 
7
8
  const isStreamingPayload = (request) => request?.body instanceof Readable ||
@@ -82,6 +83,29 @@ function isNodeJsHttp2TransientError(error) {
82
83
  return error.code === "ERR_HTTP2_STREAM_ERROR" && error.message.includes("NGHTTP2_REFUSED_STREAM");
83
84
  }
84
85
 
86
+ const race = (promise, signal) => {
87
+ if (!signal) {
88
+ return promise;
89
+ }
90
+ let cleanup = () => { };
91
+ const aborted = new Promise((_, reject) => {
92
+ const handler = () => reject(createAbortError());
93
+ if (signal.aborted) {
94
+ handler();
95
+ }
96
+ else if (typeof signal.addEventListener === "function") {
97
+ signal.addEventListener("abort", handler, { once: true });
98
+ cleanup = () => signal.removeEventListener("abort", handler);
99
+ }
100
+ else {
101
+ signal.onabort = handler;
102
+ }
103
+ });
104
+ return Promise.race([promise, aborted]).finally(cleanup);
105
+ };
106
+ const createAbortError = () => Object.assign(new Error("Request aborted"), { name: "AbortError" });
107
+ const isAbortError = (error) => typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
108
+
85
109
  const DEFAULT_RETRY_DELAY_BASE = 100;
86
110
  const MAXIMUM_RETRY_DELAY = 20 * 1000;
87
111
  const THROTTLING_RETRY_DELAY_BASE = 500;
@@ -160,9 +184,11 @@ function bindRetryMiddleware(isStreamingPayload) {
160
184
  return (options) => (next, context) => async (args) => {
161
185
  let retryStrategy = await options.retryStrategy();
162
186
  const maxAttempts = await options.maxAttempts();
187
+ const abortSignal = context[SMITHY_CONTEXT_KEY]?.abortSignal;
163
188
  if (isRetryStrategyV2(retryStrategy)) {
164
189
  retryStrategy = retryStrategy;
165
- let retryToken = await retryStrategy.acquireInitialRetryToken((context["partition_id"] ?? "") + (context.__retryLongPoll ? ":longpoll" : ""));
190
+ const retryTokenScope = (context["partition_id"] ?? "") + (context.__retryLongPoll ? ":longpoll" : "");
191
+ let retryToken = await race(retryStrategy.acquireInitialRetryToken(retryTokenScope), abortSignal);
166
192
  let lastError = new Error();
167
193
  let attempts = 0;
168
194
  let totalRetryDelay = 0;
@@ -190,9 +216,12 @@ function bindRetryMiddleware(isStreamingPayload) {
190
216
  throw lastError;
191
217
  }
192
218
  try {
193
- retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo);
219
+ retryToken = await race(retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo), abortSignal);
194
220
  }
195
- catch (ignoredRefreshError) {
221
+ catch (refreshError) {
222
+ if (abortSignal?.aborted && isAbortError(refreshError)) {
223
+ throw refreshError;
224
+ }
196
225
  if (!lastError.$metadata) {
197
226
  lastError.$metadata = {};
198
227
  }
@@ -204,7 +233,7 @@ function bindRetryMiddleware(isStreamingPayload) {
204
233
  const delay = retryToken.getRetryDelay();
205
234
  totalRetryDelay += (retryToken?.$retryLog?.acquisitionDelay ?? 0) + delay;
206
235
  if (delay > 0) {
207
- await cooldown(delay);
236
+ await race(new Promise((resolve) => setTimeout(resolve, delay)), abortSignal);
208
237
  }
209
238
  }
210
239
  }
@@ -218,7 +247,6 @@ function bindRetryMiddleware(isStreamingPayload) {
218
247
  }
219
248
  };
220
249
  }
221
- const cooldown = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
222
250
  const isRetryStrategyV2 = (retryStrategy) => typeof retryStrategy.acquireInitialRetryToken !== "undefined" &&
223
251
  typeof retryStrategy.refreshRetryTokenForRetry !== "undefined" &&
224
252
  typeof retryStrategy.recordSuccess !== "undefined";
@@ -28,6 +28,7 @@ export class Command {
28
28
  commandInstance: this,
29
29
  ...smithyContext,
30
30
  ...(options?.metricsRecorder === undefined ? {} : { metricsRecorder: options.metricsRecorder }),
31
+ ...(options?.abortSignal === undefined ? {} : { abortSignal: options.abortSignal }),
31
32
  },
32
33
  };
33
34
  const { requestHandler } = configuration;
@@ -1,7 +1,9 @@
1
1
  import { NoOpLogger } from "@smithy/core/client";
2
2
  import { HttpRequest } from "@smithy/core/protocols";
3
3
  import { v4 } from "@smithy/core/serde";
4
+ import { SMITHY_CONTEXT_KEY } from "@smithy/types";
4
5
  import { isServerError, isThrottlingError, isTransientError, } from "../service-error-classification/service-error-classification";
6
+ import { isAbortError, race } from "../util-retry/race";
5
7
  import { INVOCATION_ID_HEADER, REQUEST_HEADER } from "../util-retry/constants";
6
8
  import { parseRetryAfterHeader } from "./parseRetryAfterHeader";
7
9
  import { asSdkError } from "./util";
@@ -9,9 +11,11 @@ export function bindRetryMiddleware(isStreamingPayload) {
9
11
  return (options) => (next, context) => async (args) => {
10
12
  let retryStrategy = await options.retryStrategy();
11
13
  const maxAttempts = await options.maxAttempts();
14
+ const abortSignal = context[SMITHY_CONTEXT_KEY]?.abortSignal;
12
15
  if (isRetryStrategyV2(retryStrategy)) {
13
16
  retryStrategy = retryStrategy;
14
- let retryToken = await retryStrategy.acquireInitialRetryToken((context["partition_id"] ?? "") + (context.__retryLongPoll ? ":longpoll" : ""));
17
+ const retryTokenScope = (context["partition_id"] ?? "") + (context.__retryLongPoll ? ":longpoll" : "");
18
+ let retryToken = await race(retryStrategy.acquireInitialRetryToken(retryTokenScope), abortSignal);
15
19
  let lastError = new Error();
16
20
  let attempts = 0;
17
21
  let totalRetryDelay = 0;
@@ -39,9 +43,12 @@ export function bindRetryMiddleware(isStreamingPayload) {
39
43
  throw lastError;
40
44
  }
41
45
  try {
42
- retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo);
46
+ retryToken = await race(retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo), abortSignal);
43
47
  }
44
- catch (ignoredRefreshError) {
48
+ catch (refreshError) {
49
+ if (abortSignal?.aborted && isAbortError(refreshError)) {
50
+ throw refreshError;
51
+ }
45
52
  if (!lastError.$metadata) {
46
53
  lastError.$metadata = {};
47
54
  }
@@ -53,7 +60,7 @@ export function bindRetryMiddleware(isStreamingPayload) {
53
60
  const delay = retryToken.getRetryDelay();
54
61
  totalRetryDelay += (retryToken?.$retryLog?.acquisitionDelay ?? 0) + delay;
55
62
  if (delay > 0) {
56
- await cooldown(delay);
63
+ await race(new Promise((resolve) => setTimeout(resolve, delay)), abortSignal);
57
64
  }
58
65
  }
59
66
  }
@@ -67,7 +74,6 @@ export function bindRetryMiddleware(isStreamingPayload) {
67
74
  }
68
75
  };
69
76
  }
70
- const cooldown = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
71
77
  const isRetryStrategyV2 = (retryStrategy) => typeof retryStrategy.acquireInitialRetryToken !== "undefined" &&
72
78
  typeof retryStrategy.refreshRetryTokenForRetry !== "undefined" &&
73
79
  typeof retryStrategy.recordSuccess !== "undefined";
@@ -0,0 +1,22 @@
1
+ export const race = (promise, signal) => {
2
+ if (!signal) {
3
+ return promise;
4
+ }
5
+ let cleanup = () => { };
6
+ const aborted = new Promise((_, reject) => {
7
+ const handler = () => reject(createAbortError());
8
+ if (signal.aborted) {
9
+ handler();
10
+ }
11
+ else if (typeof signal.addEventListener === "function") {
12
+ signal.addEventListener("abort", handler, { once: true });
13
+ cleanup = () => signal.removeEventListener("abort", handler);
14
+ }
15
+ else {
16
+ signal.onabort = handler;
17
+ }
18
+ });
19
+ return Promise.race([promise, aborted]).finally(cleanup);
20
+ };
21
+ const createAbortError = () => Object.assign(new Error("Request aborted"), { name: "AbortError" });
22
+ export const isAbortError = (error) => typeof error === "object" && error !== null && "name" in error && error.name === "AbortError";
@@ -0,0 +1,3 @@
1
+ import type { AbortSignal as DeprecatedAbortSignal } from "@smithy/types";
2
+ export declare const race: <T>(promise: Promise<T>, signal?: AbortSignal | DeprecatedAbortSignal) => Promise<T>;
3
+ export declare const isAbortError: (error: unknown) => boolean;
@@ -0,0 +1,3 @@
1
+ import { AbortSignal as DeprecatedAbortSignal } from "@smithy/types";
2
+ export declare const race: <T>(promise: Promise<T>, signal?: AbortSignal | DeprecatedAbortSignal) => Promise<T>;
3
+ export declare const isAbortError: (error: unknown) => boolean;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/core",
3
- "version": "3.38.1",
3
+ "version": "3.39.0",
4
4
  "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/core",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -242,7 +242,7 @@
242
242
  "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts"
243
243
  },
244
244
  "dependencies": {
245
- "@smithy/types": "^4.19.0",
245
+ "@smithy/types": "^4.20.0",
246
246
  "tslib": "^2.6.2"
247
247
  },
248
248
  "devDependencies": {
@@ -7,15 +7,17 @@ function createRequest(url, requestOptions) {
7
7
  }
8
8
 
9
9
  function requestTimeout(timeoutInMs = 0) {
10
- return new Promise((resolve, reject) => {
10
+ let timeoutId;
11
+ const promise = new Promise((resolve, reject) => {
11
12
  if (timeoutInMs) {
12
- setTimeout(() => {
13
+ timeoutId = setTimeout(() => {
13
14
  const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
14
15
  timeoutError.name = "TimeoutError";
15
16
  reject(timeoutError);
16
17
  }, timeoutInMs);
17
18
  }
18
19
  });
20
+ return { promise, cancel: () => clearTimeout(timeoutId) };
19
21
  }
20
22
 
21
23
  const keepAliveSupport = {
@@ -95,6 +97,7 @@ class FetchHttpHandler {
95
97
  Object.assign(requestOptions, this.config.requestInit(request));
96
98
  }
97
99
  let removeSignalEventListener = () => { };
100
+ const timeout = requestTimeout(requestTimeoutInMs);
98
101
  const fetchRequest = createRequest(url, requestOptions);
99
102
  const raceOfPromises = [
100
103
  fetchFn(fetchRequest).then((response) => {
@@ -123,7 +126,7 @@ class FetchHttpHandler {
123
126
  }),
124
127
  };
125
128
  }),
126
- requestTimeout(requestTimeoutInMs),
129
+ timeout.promise,
127
130
  ];
128
131
  if (abortSignal) {
129
132
  raceOfPromises.push(new Promise((resolve, reject) => {
@@ -141,7 +144,10 @@ class FetchHttpHandler {
141
144
  }
142
145
  }));
143
146
  }
144
- return Promise.race(raceOfPromises).finally(removeSignalEventListener);
147
+ return Promise.race(raceOfPromises).finally(() => {
148
+ timeout.cancel();
149
+ removeSignalEventListener();
150
+ });
145
151
  }
146
152
  updateHttpClientConfig(key, value) {
147
153
  this.config = undefined;
@@ -78,6 +78,7 @@ export class FetchHttpHandler {
78
78
  Object.assign(requestOptions, this.config.requestInit(request));
79
79
  }
80
80
  let removeSignalEventListener = () => { };
81
+ const timeout = requestTimeoutFn(requestTimeoutInMs);
81
82
  const fetchRequest = createRequest(url, requestOptions);
82
83
  const raceOfPromises = [
83
84
  fetchFn(fetchRequest).then((response) => {
@@ -106,7 +107,7 @@ export class FetchHttpHandler {
106
107
  }),
107
108
  };
108
109
  }),
109
- requestTimeoutFn(requestTimeoutInMs),
110
+ timeout.promise,
110
111
  ];
111
112
  if (abortSignal) {
112
113
  raceOfPromises.push(new Promise((resolve, reject) => {
@@ -124,7 +125,10 @@ export class FetchHttpHandler {
124
125
  }
125
126
  }));
126
127
  }
127
- return Promise.race(raceOfPromises).finally(removeSignalEventListener);
128
+ return Promise.race(raceOfPromises).finally(() => {
129
+ timeout.cancel();
130
+ removeSignalEventListener();
131
+ });
128
132
  }
129
133
  updateHttpClientConfig(key, value) {
130
134
  this.config = undefined;
@@ -1,11 +1,13 @@
1
1
  export function requestTimeout(timeoutInMs = 0) {
2
- return new Promise((resolve, reject) => {
2
+ let timeoutId;
3
+ const promise = new Promise((resolve, reject) => {
3
4
  if (timeoutInMs) {
4
- setTimeout(() => {
5
+ timeoutId = setTimeout(() => {
5
6
  const timeoutError = new Error(`Request did not complete within ${timeoutInMs} ms`);
6
7
  timeoutError.name = "TimeoutError";
7
8
  reject(timeoutError);
8
9
  }, timeoutInMs);
9
10
  }
10
11
  });
12
+ return { promise, cancel: () => clearTimeout(timeoutId) };
11
13
  }
@@ -1 +1,12 @@
1
- export declare function requestTimeout(timeoutInMs?: number): Promise<never>;
1
+ /**
2
+ * Rejects with a TimeoutError after `timeoutInMs` (never, for 0).
3
+ *
4
+ * Call `cancel` once the request settles: a pending timer keeps the request
5
+ * race, and the response it settled with, reachable until the timer fires.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare function requestTimeout(timeoutInMs?: number): {
10
+ promise: Promise<never>;
11
+ cancel: () => void;
12
+ };
@@ -1 +1,12 @@
1
- export declare function requestTimeout(timeoutInMs?: number): Promise<never>;
1
+ /**
2
+ * Rejects with a TimeoutError after `timeoutInMs` (never, for 0).
3
+ *
4
+ * Call `cancel` once the request settles: a pending timer keeps the request
5
+ * race, and the response it settled with, reachable until the timer fires.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare function requestTimeout(timeoutInMs?: number): {
10
+ promise: Promise<never>;
11
+ cancel: () => void;
12
+ };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/fetch-http-handler",
3
- "version": "5.8.0",
3
+ "version": "5.8.1",
4
4
  "description": "Provides a way to make requests",
5
5
  "homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/fetch-http-handler",
6
6
  "license": "Apache-2.0",
@@ -40,8 +40,8 @@
40
40
  "test:browser:watch": "yarn g:vitest watch -c vitest.config.browser.mts"
41
41
  },
42
42
  "dependencies": {
43
- "@smithy/core": "^3.33.3",
44
- "@smithy/types": "^4.18.0",
43
+ "@smithy/core": "^3.39.0",
44
+ "@smithy/types": "^4.20.0",
45
45
  "tslib": "^2.6.2"
46
46
  },
47
47
  "devDependencies": {