-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(aws-cdk-lib): temporary Cloud Assemblies are not cleaned up #36043
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This review is outdated)
e1ee38c to
177173e
Compare
The CDK framework creates a temporary directory in `/tmp` for every unit test, and never cleans those up. In this PR, register all temporary assembly directories created by doing `new Stack()` or `new App()` without an `outdir`, and delete them when the Node process exits. This will only affect unit tests: if the `outdir` property is set explicitly, or the CDK App is being synthesized by the CLI (and `$CDK_OUTDIR` is set), the assembly directory will not be cleaned.
177173e to
408e4a8
Compare
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
| // On process exit, delete all temporary assembly directories | ||
| const TEMPORARY_ASSEMBLY_DIRS: string[] = []; | ||
| process.on('exit', () => { | ||
| for (const dir of TEMPORARY_ASSEMBLY_DIRS) { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: This scares me a little. But I guess it's safe because the only way that an outside caller of the app would know about the outdir, is by providing it explicitly to the app. So our rule is now:
- Need the CloudAssembly? Provide an outdir.
- Otherwise, we synth but the result is lost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's my thought. If you didn't provide a path, are you going to dig the assembly directory out of /tmp, amongst the 3000 other assemblies there? I don't think so.
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
|
Comments on closed issues and PRs are hard for our team to see. |
The CDK framework creates a temporary directory in
/tmpfor every unit test, and never cleans those up.In this PR, register all temporary assembly directories created by doing
new Stack()ornew App()without anoutdir, and delete them when the Node process exits.This will only affect unit tests: if the
outdirproperty is set explicitly, or the CDK App is being synthesized by the CLI (and$CDK_OUTDIRis set), the assembly directory will not be cleaned. For users: if you setoutdiryou are reponsible for cleaning up the directory. If you don't setoutdir, it will be automatically removed at some point.This will benefit both
aws-cdkdevelopment itself, as well as users writing unit tests against CDK.Relates to #802.
Also in this PR: cleanup of other temporary directories we create during tests. These will only benefit development on
aws-cdkitself.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license