Skip to content

Commit 89fd917

Browse files
committed
add retry for cdk migrate java & fetchDockerLoginCredential
1 parent df83ecf commit 89fd917

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { deploysSuccessfully } from './testcase';
2-
import { integTest, withCDKMigrateFixture } from '../../../lib';
2+
import { integTest, withCDKMigrateFixture, withRetry } from '../../../lib';
33

44
const language = 'java';
55

66
jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime
77

88
integTest(
99
`cdk migrate ${language} deploys successfully`,
10-
withCDKMigrateFixture(language, async (fixture) => {
10+
withRetry(withCDKMigrateFixture(language, async (fixture) => {
1111
await deploysSuccessfully(fixture, language);
12-
}),
12+
})),
1313
);

packages/cdk-assets/bin/docker-credential-cdk-assets.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,32 @@ async function main() {
3939

4040
// Read the domain to fetch from stdin
4141
let endpoint = fs.readFileSync(0, { encoding: 'utf-8' }).trim();
42-
const credentials = await fetchDockerLoginCredentials(new DefaultAwsClient(), config, endpoint);
43-
// Write the credentials back to stdout
44-
fs.writeFileSync(1, JSON.stringify(credentials));
42+
43+
const deadline = Date.now() + 60_000; // 60 seconds timeout
44+
let lastError: Error | undefined;
45+
46+
while (Date.now() < deadline) {
47+
try {
48+
const credentials = await fetchDockerLoginCredentials(new DefaultAwsClient(), config, endpoint);
49+
// Write the credentials back to stdout
50+
fs.writeFileSync(1, JSON.stringify(credentials));
51+
return;
52+
} catch (e: any) {
53+
lastError = e;
54+
55+
// Retry on AccessDenied errors due to eventual consistency in AWS IAM.
56+
// Newly created roles and policies may take time to propagate across regions.
57+
if (e.name === 'AccessDenied') {
58+
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds
59+
continue;
60+
}
61+
62+
// For other errors, throw immediately
63+
throw e;
64+
}
65+
}
66+
67+
throw lastError;
4568
}
4669

4770
main().catch((e) => {

0 commit comments

Comments
 (0)