Skip to content
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(cdk): changed retry mechanism for hotswapping AppSync.function #32179

Merged
merged 24 commits into from
Dec 12, 2024
Merged
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
044c874
fix: hotswap for functions uses exponential backoff
ShadowCat567 Nov 18, 2024
2d869f2
fix: implement base backoff as 1 second
ShadowCat567 Nov 18, 2024
633c9ea
fix: added retry limit
ShadowCat567 Nov 19, 2024
1d90f3e
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Nov 19, 2024
d879bb6
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Nov 19, 2024
50672c8
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Nov 22, 2024
3617bfa
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Nov 25, 2024
ffbdaa8
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 6, 2024
8dfb7b3
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 6, 2024
249b389
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 6, 2024
b782d07
update test coverage
ShadowCat567 Dec 9, 2024
ddc789f
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 9, 2024
dfb2680
update to unit test
ShadowCat567 Dec 9, 2024
d7bb780
Merge branch 'amplify-exp-backoff' of https://github.com/ShadowCat567…
ShadowCat567 Dec 9, 2024
63b1bfd
update to error rejection
ShadowCat567 Dec 9, 2024
7de6463
back off retry test
ShadowCat567 Dec 10, 2024
0b657ba
update failed attempt count
ShadowCat567 Dec 10, 2024
07008e2
fix test
Amplifiyer Dec 10, 2024
da730ed
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 10, 2024
a8fc54f
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 10, 2024
b0ee49d
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 11, 2024
66870fa
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 11, 2024
ac51361
Merge branch 'main' into amplify-exp-backoff
ShadowCat567 Dec 11, 2024
56e0f44
Merge branch 'main' into amplify-exp-backoff
mergify[bot] Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ export async function isHotswappableAppSyncChange(
const functions = await sdk.appsync().listFunctions({ apiId: sdkRequestObject.apiId });
const { functionId } = functions.find((fn) => fn.name === physicalName) ?? {};
// Updating multiple functions at the same time or along with graphql schema results in `ConcurrentModificationException`
await simpleRetry(
await exponentialBackoffRetry(
() =>
sdk.appsync().updateFunction({
...sdkRequestObject,
functionId: functionId,
}),
5,
1000,
'ConcurrentModificationException',
);
} else if (isGraphQLSchema) {
Expand Down Expand Up @@ -169,13 +169,13 @@ async function fetchFileFromS3(s3Url: string, sdk: SDK) {
return (await sdk.s3().getObject({ Bucket: s3Bucket, Key: s3Key })).Body?.transformToString();
}

async function simpleRetry(fn: () => Promise<any>, numOfRetries: number, errorCodeToRetry: string) {
async function exponentialBackoffRetry(fn: () => Promise<any>, backoff: number, errorCodeToRetry: string) {
try {
await fn();
} catch (error: any) {
if (error && error.name === errorCodeToRetry && numOfRetries > 0) {
await sleep(1000); // wait a whole second
await simpleRetry(fn, numOfRetries - 1, errorCodeToRetry);
if (error && error.name === errorCodeToRetry) {
await sleep(backoff); // time to wait doubles everytime function fails, starts at 1 second
await exponentialBackoffRetry(fn, backoff * 2, errorCodeToRetry);
} else {
throw error;
}
Expand Down
Loading