fix: prevent deadlock when cross-region CDK stacks share the same stack name - #652
Merged
Merged
Conversation
…ck name When two cross-region stacks share the same CloudFormation stack name (e.g. a CloudFront us-east-1 support stack reusing the main stack name via the stackName property), the dependency graph was keyed by StackName. The two distinct stacks collapsed into one map entry, so no stack ever reached in-degree 0 and the deletion loop blocked forever (deadlock). Use the unique Cloud Assembly artifact key as the graph identity instead: - StackInfo gains an Identifier field and stores dependencies as artifact keys (unambiguous when stack names collide). - CdkDeleter keys its graph by identity and deletes by StackName + Region. - Stack selection dedups by identity so both same-named cross-region stacks are selectable via -s.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
delstack cdkdeadlocks when two cross-region stacks share the same CloudFormation stack name:This happens with a common CDK pattern: a CloudFront
us-east-1support stack reuses the main stack's CloudFormation name via thestackNameproperty. Both stacks resolve to the sameStackName(e.g.AiApi), living in different regions.Root cause
CdkDeleterbuilds its reverse-topological dependency graph keyed byStackName. When two distinct stacks share a name:stackMapcollapses to a single entry.reverseInDegree == 1.Additionally,
Dependencieswere stored as resolved stack names, which are ambiguous when names collide across regions.Fix
Use the unique Cloud Assembly artifact key as the graph identity:
StackInfogains anIdentifierfield, andDependenciesnow hold artifact keys instead of resolved stack names.CdkDeleterkeys its graph by identity (stackIdentity, falling back toStackNamewhen unset) and deletes byStackName+Region.-s) dedups by identity, fixing a related latent bug where only one of two same-named cross-region stacks was selectable.Tests
TestCdkDeleter_DeleteStacks_CrossRegionDeps_SameStackNamereproduces the reported deadlock using a mock executor (no real AWS calls).TestParseManifest_CrossRegionSameStackNamecovers parsing a manifest wherestackNameoverride causes a name collision.No real stacks were deleted during verification; the regression test with mocks confirms the fix.