-
Notifications
You must be signed in to change notification settings - Fork 582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(util-retry): use different retry token instances per request #4755
Conversation
d3cb733
to
2269a41
Compare
In the offline discussion, we decided to deprecate the following functions from
Although They have access to availableCapacity, and can modify it. |
2bd3423
to
cdaf93d
Compare
Verified the fix by printing import {
S3Client,
ListBucketsCommand,
ListObjectsCommand,
} from "../aws-sdk-js-v3/clients/client-s3/dist-cjs/index.js";
import {
DynamoDBClient,
ListTablesCommand,
ListBackupsCommand,
} from "../aws-sdk-js-v3/clients/client-dynamodb/dist-cjs/index.js";
import { NodeHttpHandler } from "../aws-sdk-js-v3/packages/node-http-handler/dist-cjs/index.js";
import { ConfiguredRetryStrategy } from "../aws-sdk-js-v3/packages/util-retry/dist-cjs/index.js";
// Simulate a timeout error.
class NodeHttpHandlerReturnsTimeout extends NodeHttpHandler {
async handle(request, options) {
const timeoutError = new Error("Request timed out");
timeoutError.name = "TimeoutError";
throw timeoutError;
}
}
const s3Client = new S3Client({
region: "us-west-2",
requestHandler: new NodeHttpHandlerReturnsTimeout(),
retryStrategy: new ConfiguredRetryStrategy(2, () => 100),
});
const dynamodbClient = new DynamoDBClient({
region: "us-west-2",
requestHandler: new NodeHttpHandlerReturnsTimeout(),
retryStrategy: new ConfiguredRetryStrategy(3, () => 50),
});
const calls = {};
const callRequest = async (client, command, operation) => {
if (!calls[operation]) {
calls[operation] = 0;
}
while (true) {
try {
await client.send(command);
} catch (error) {
const metadata = error.$metadata;
calls[operation] = calls[operation] + 1;
console.log(
`[${operation}]: Call #${calls[operation]}, Attempts: ${metadata.attempts}, Retry delay: ${metadata.totalRetryDelay}ms`
);
if (calls[operation] === 3) {
break;
}
}
}
};
await Promise.all([
callRequest(s3Client, new ListBucketsCommand({}), "s3:listBuckets"),
callRequest(
s3Client,
new ListObjectsCommand({ Bucket: "foo" }),
"s3:listObjects"
),
callRequest(dynamodbClient, new ListTablesCommand({}), "ddb:listTables"),
callRequest(dynamodbClient, new ListBackupsCommand({}), "ddb:listBackups"),
]); |
…methods on standard retry token
Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Issue
#4754
Description
Use different instances of the retry token when new requests are made from the same client. They will however share the token availability if coming from the same client and RetryStrategy instance.
Currently, because the retry token object and its closure persist between calls of the same client using the same StandardRetryStrategy instance, the retry count stays at its max value.
Testing