DefaultStackSynthesizer: App level synthesizer leaks assets between Stacks when specified #29071
Labels
@aws-cdk/assets
Related to the @aws-cdk/assets package
bug
This issue is a bug.
effort/medium
Medium work item – several days of effort
p2
Describe the bug
I am working on a multi-stack App with multiple specified account targets (via the env property on each Stack). When specifying the property defaultStackSynthesizer on the App I started facing deployment issues I had never faced before. The output implied that the specific Stack I was trying to deploy wanted to publish assets belonging to other stacks.
By looking at the manifest for each Stack I was able to verify this. This issue does not present itself if you have all Stacks configured to deploy to the same account. I assume the same goes if they are all account agnostic. While the deployment failures are not irrelevant I think the underlying issue of the wrong assets being added to manifests is the key here.
Expected Behavior
The Stack manifests only contain relevant files.
Current Behavior
The Stack manifests contains assets belonging to other stacks. Screenshot of manifest for Stack attached to App after another Stack:
Note how it not only contains its own template but also the template for StackA.
Reproduction Steps
I have also taken the liberty of creating a repository which highlights the issue: CDK Assets leak. The cdk.out directory is commited and this file highlights the issue with more than one template being present.
Possible Solution
I have located the source of the issue in DefaultStackSynthesizer. It stems from reusableBind
It copies the DefaultStackSynthesizer, however this only partially works since the class instance contains another class instance and the reference is kept. The reference to the assetManifest is kept and all Stacks end up sharing the same AssetManifestBuilder.
This snippet of code highlights why this is an issue:
Additional Information/Context
I will create a PR soon that should fix this.
CDK CLI Version
2.127.0 (build 6c90efc)
Framework Version
No response
Node.js Version
v20.10.0
OS
Sonoma 14.2.1
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: