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

DefaultStackSynthesizer: App level synthesizer leaks assets between Stacks when specified #29071

Open
castodius opened this issue Feb 11, 2024 · 1 comment
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

Comments

@castodius
Copy link

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:
image

Note how it not only contains its own template but also the template for StackA.

Reproduction Steps

  1. Create a new project using "npx cdk init app --language=typescript"
  2. Modify the app to instantiate a DefaultStackSynthesizer, no props needed
  3. Add two Stacks that use this App as scope
  4. Synth using "npx cdk synth"
  5. Check Stack manifests under cdk.out

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
image

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.
image

This snippet of code highlights why this is an issue:

const helper = {
  value: 1
}

const wrapper = {
  foo: helper
}

// prints 1
console.log(wrapper.foo.value)

const copy1 = Object.create(wrapper)
copy1.foo.value = 2

// prints 2 since the reference to helper was kept
console.log(wrapper.foo.value)

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

@pahud
Copy link
Contributor

pahud commented Feb 13, 2024

Thank you for the report and we appreciate your PR.

@pahud pahud added p2 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
2 participants