Skip to content

Commit

Permalink
fix(cdk-assets): asset concurrency leaves a corrupted archive (#24026)
Browse files Browse the repository at this point in the history
This is a re-roll of #23677 which was reverted in #23994 because the `randomUUID()` function from the original solution was not available in Node versions below 14.17 (and we advertise compatibility with Node 14.*).

We didn't actually need a UUID, just any random string, so replace it with a function that generates a random string in a different way.

----------

Resolves #23290

A very simple fix for the issue where builds with `--concurrency` specified can lead to corrupt archives. Rather than use the outputFile as the basis for the temp file name we simply use a random string.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
rix0rrr authored Feb 6, 2023
1 parent 0b20bc5 commit 989454f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/cdk-assets/lib/private/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Logger = (x: string) => void;
export async function zipDirectory(directory: string, outputFile: string, logger: Logger): Promise<void> {
// We write to a temporary file and rename at the last moment. This is so that if we are
// interrupted during this process, we don't leave a half-finished file in the target location.
const temporaryOutputFile = `${outputFile}._tmp`;
const temporaryOutputFile = `${outputFile}.${randomString()}._tmp`;
await writeZipFile(directory, temporaryOutputFile);
await moveIntoPlace(temporaryOutputFile, outputFile, logger);
}
Expand Down Expand Up @@ -96,4 +96,8 @@ async function pathExists(x: string) {
}
throw e;
}
}

function randomString() {
return Math.random().toString(36).replace(/[^a-z0-9]+/g, '');
}

0 comments on commit 989454f

Please sign in to comment.