@smithy/core 3.38.1 → 3.40.0
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.
- package/CHANGELOG.md +17 -0
- package/dist-cjs/submodules/client/index.js +1 -0
- package/dist-cjs/submodules/retry/index.browser.js +41 -13
- package/dist-cjs/submodules/retry/index.js +41 -13
- package/dist-es/submodules/client/smithy-client/command.js +1 -0
- package/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +11 -5
- package/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +2 -2
- package/dist-es/submodules/retry/util-retry/race.js +22 -0
- package/dist-es/submodules/retry/util-retry/retries-2026-config.js +6 -6
- package/dist-types/submodules/retry/util-retry/race.d.ts +3 -0
- package/dist-types/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
- package/dist-types/ts3.4/submodules/retry/util-retry/race.d.ts +3 -0
- package/dist-types/ts3.4/submodules/retry/util-retry/retries-2026-config.d.ts +16 -6
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.40.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8d835c3: Enable the 2026 standard retry behavior unconditionally. The `SMITHY_NEW_RETRIES_2026` environment variable is no longer read. Standard and adaptive modes now default to a 50 ms base delay for non-throttling errors and a 1 s base delay for throttling errors, retry quota costs of 14 (non-throttling) and 5 (throttling), and apply backoff to long-polling operations when the retry quota is exhausted.
|
|
8
|
+
|
|
9
|
+
## 3.39.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d5e8c96: Return `AbortError` immediately when an operation is aborted during retry-token acquisition, backoff, or custom retry-token delays.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [d5e8c96]
|
|
18
|
+
- @smithy/types@4.20.0
|
|
19
|
+
|
|
3
20
|
## 3.38.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
|
@@ -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
|
-
|
|
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 (
|
|
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
|
|
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";
|
|
@@ -371,21 +399,21 @@ class DefaultRateLimiter {
|
|
|
371
399
|
}
|
|
372
400
|
|
|
373
401
|
class Retry {
|
|
374
|
-
static v2026 =
|
|
402
|
+
static v2026 = true;
|
|
375
403
|
static delay() {
|
|
376
|
-
return
|
|
404
|
+
return 50;
|
|
377
405
|
}
|
|
378
406
|
static throttlingDelay() {
|
|
379
|
-
return
|
|
407
|
+
return 1_000;
|
|
380
408
|
}
|
|
381
409
|
static cost() {
|
|
382
|
-
return
|
|
410
|
+
return 14;
|
|
383
411
|
}
|
|
384
412
|
static throttlingCost() {
|
|
385
|
-
return
|
|
413
|
+
return 5;
|
|
386
414
|
}
|
|
387
415
|
static modifiedCostType() {
|
|
388
|
-
return
|
|
416
|
+
return "THROTTLING";
|
|
389
417
|
}
|
|
390
418
|
}
|
|
391
419
|
|
|
@@ -466,7 +494,7 @@ let StandardRetryStrategy$1 = class StandardRetryStrategy {
|
|
|
466
494
|
this.retryBackoffStrategy ??= new DefaultRetryBackoffStrategy();
|
|
467
495
|
}
|
|
468
496
|
async acquireInitialRetryToken(retryTokenScope) {
|
|
469
|
-
return new DefaultRetryToken(Retry.delay(), 0, undefined,
|
|
497
|
+
return new DefaultRetryToken(Retry.delay(), 0, undefined, retryTokenScope.includes(":longpoll"));
|
|
470
498
|
}
|
|
471
499
|
async refreshRetryTokenForRetry(token, errorInfo) {
|
|
472
500
|
const maxAttempts = await this.getMaxAttempts();
|
|
@@ -482,7 +510,7 @@ let StandardRetryStrategy$1 = class StandardRetryStrategy {
|
|
|
482
510
|
retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
|
|
483
511
|
}
|
|
484
512
|
if (!shouldRetry) {
|
|
485
|
-
const longPollBackoff =
|
|
513
|
+
const longPollBackoff = retryCode === refusal.capacity && isLongPoll ? retryDelay : 0;
|
|
486
514
|
if (longPollBackoff > 0) {
|
|
487
515
|
await new Promise((r) => setTimeout(r, longPollBackoff));
|
|
488
516
|
}
|
|
@@ -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
|
-
|
|
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 (
|
|
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
|
|
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";
|
|
@@ -373,21 +401,21 @@ class DefaultRateLimiter {
|
|
|
373
401
|
}
|
|
374
402
|
|
|
375
403
|
class Retry {
|
|
376
|
-
static v2026 =
|
|
404
|
+
static v2026 = true;
|
|
377
405
|
static delay() {
|
|
378
|
-
return
|
|
406
|
+
return 50;
|
|
379
407
|
}
|
|
380
408
|
static throttlingDelay() {
|
|
381
|
-
return
|
|
409
|
+
return 1_000;
|
|
382
410
|
}
|
|
383
411
|
static cost() {
|
|
384
|
-
return
|
|
412
|
+
return 14;
|
|
385
413
|
}
|
|
386
414
|
static throttlingCost() {
|
|
387
|
-
return
|
|
415
|
+
return 5;
|
|
388
416
|
}
|
|
389
417
|
static modifiedCostType() {
|
|
390
|
-
return
|
|
418
|
+
return "THROTTLING";
|
|
391
419
|
}
|
|
392
420
|
}
|
|
393
421
|
|
|
@@ -468,7 +496,7 @@ let StandardRetryStrategy$1 = class StandardRetryStrategy {
|
|
|
468
496
|
this.retryBackoffStrategy ??= new DefaultRetryBackoffStrategy();
|
|
469
497
|
}
|
|
470
498
|
async acquireInitialRetryToken(retryTokenScope) {
|
|
471
|
-
return new DefaultRetryToken(Retry.delay(), 0, undefined,
|
|
499
|
+
return new DefaultRetryToken(Retry.delay(), 0, undefined, retryTokenScope.includes(":longpoll"));
|
|
472
500
|
}
|
|
473
501
|
async refreshRetryTokenForRetry(token, errorInfo) {
|
|
474
502
|
const maxAttempts = await this.getMaxAttempts();
|
|
@@ -484,7 +512,7 @@ let StandardRetryStrategy$1 = class StandardRetryStrategy {
|
|
|
484
512
|
retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
|
|
485
513
|
}
|
|
486
514
|
if (!shouldRetry) {
|
|
487
|
-
const longPollBackoff =
|
|
515
|
+
const longPollBackoff = retryCode === refusal.capacity && isLongPoll ? retryDelay : 0;
|
|
488
516
|
if (longPollBackoff > 0) {
|
|
489
517
|
await new Promise((r) => setTimeout(r, longPollBackoff));
|
|
490
518
|
}
|
|
@@ -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
|
-
|
|
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 (
|
|
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
|
|
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";
|
|
@@ -31,7 +31,7 @@ export class StandardRetryStrategy {
|
|
|
31
31
|
this.retryBackoffStrategy ??= new DefaultRetryBackoffStrategy();
|
|
32
32
|
}
|
|
33
33
|
async acquireInitialRetryToken(retryTokenScope) {
|
|
34
|
-
return new DefaultRetryToken(Retry.delay(), 0, undefined,
|
|
34
|
+
return new DefaultRetryToken(Retry.delay(), 0, undefined, retryTokenScope.includes(":longpoll"));
|
|
35
35
|
}
|
|
36
36
|
async refreshRetryTokenForRetry(token, errorInfo) {
|
|
37
37
|
const maxAttempts = await this.getMaxAttempts();
|
|
@@ -47,7 +47,7 @@ export class StandardRetryStrategy {
|
|
|
47
47
|
retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
|
|
48
48
|
}
|
|
49
49
|
if (!shouldRetry) {
|
|
50
|
-
const longPollBackoff =
|
|
50
|
+
const longPollBackoff = retryCode === refusal.capacity && isLongPoll ? retryDelay : 0;
|
|
51
51
|
if (longPollBackoff > 0) {
|
|
52
52
|
await new Promise((r) => setTimeout(r, longPollBackoff));
|
|
53
53
|
}
|
|
@@ -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";
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export class Retry {
|
|
2
|
-
static v2026 =
|
|
2
|
+
static v2026 = true;
|
|
3
3
|
static delay() {
|
|
4
|
-
return
|
|
4
|
+
return 50;
|
|
5
5
|
}
|
|
6
6
|
static throttlingDelay() {
|
|
7
|
-
return
|
|
7
|
+
return 1_000;
|
|
8
8
|
}
|
|
9
9
|
static cost() {
|
|
10
|
-
return
|
|
10
|
+
return 14;
|
|
11
11
|
}
|
|
12
12
|
static throttlingCost() {
|
|
13
|
-
return
|
|
13
|
+
return 5;
|
|
14
14
|
}
|
|
15
15
|
static modifiedCostType() {
|
|
16
|
-
return
|
|
16
|
+
return "THROTTLING";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Retry parameters used by the standard retry strategy.
|
|
3
|
+
*
|
|
4
|
+
* The public constants in `./constants` keep their earlier values, which the
|
|
5
|
+
* deprecated pre-SRA retry strategy still uses.
|
|
6
|
+
*
|
|
2
7
|
* @internal
|
|
3
8
|
*/
|
|
4
9
|
export declare abstract class Retry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static
|
|
10
|
+
/**
|
|
11
|
+
* Always true. Kept because previously published packages read this flag.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated the 2026 retry behavior is always enabled. May be removed in a future major version.
|
|
14
|
+
*/
|
|
15
|
+
static readonly v2026 = true;
|
|
16
|
+
static delay(): number;
|
|
17
|
+
static throttlingDelay(): number;
|
|
18
|
+
static cost(): number;
|
|
19
|
+
static throttlingCost(): number;
|
|
20
|
+
static modifiedCostType(): "THROTTLING";
|
|
11
21
|
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
+
* Retry parameters used by the standard retry strategy.
|
|
3
|
+
*
|
|
4
|
+
* The public constants in `./constants` keep their earlier values, which the
|
|
5
|
+
* deprecated pre-SRA retry strategy still uses.
|
|
6
|
+
*
|
|
2
7
|
* @internal
|
|
3
8
|
*/
|
|
4
9
|
export declare abstract class Retry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static
|
|
10
|
+
/**
|
|
11
|
+
* Always true. Kept because previously published packages read this flag.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated the 2026 retry behavior is always enabled. May be removed in a future major version.
|
|
14
|
+
*/
|
|
15
|
+
static readonly v2026 = true;
|
|
16
|
+
static delay(): number;
|
|
17
|
+
static throttlingDelay(): number;
|
|
18
|
+
static cost(): number;
|
|
19
|
+
static throttlingCost(): number;
|
|
20
|
+
static modifiedCostType(): "THROTTLING";
|
|
11
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.40.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.
|
|
245
|
+
"@smithy/types": "^4.20.0",
|
|
246
246
|
"tslib": "^2.6.2"
|
|
247
247
|
},
|
|
248
248
|
"devDependencies": {
|