fix: resolve entity expansion limit for container deploys#594
Open
jesseturner21 wants to merge 1 commit intomainfrom
Open
fix: resolve entity expansion limit for container deploys#594jesseturner21 wants to merge 1 commit intomainfrom
jesseturner21 wants to merge 1 commit intomainfrom
Conversation
The fast-xml-parser v5.x library defaults maxTotalExpansions to 1000. Container build stacks create enough CloudFormation resources that DescribeStackEvents XML responses exceed this limit (1015+ entities), causing CDK deploy to fail with "Entity expansion limit exceeded". Patch XMLParser.prototype.parse to raise the limit to 100000 before every parse call. The fast-xml-parser CJS bundle uses non-configurable webpack getters, so we cannot replace the XMLParser constructor — but prototype methods are writable. The module name is split in the require call to prevent esbuild from bundling it, ensuring the patch targets the same node_modules copy that @aws-cdk/toolkit-lib loads at runtime. Also improve e2e test teardown to handle stacks in ROLLBACK_COMPLETE or ROLLBACK_FAILED states by deleting them directly via CloudFormation API, with a fallback for normal teardown failures. Constraint: fast-xml-parser exports are configurable:false (webpack getter) Constraint: @aws-cdk/toolkit-lib is externalized by esbuild, so it uses the node_modules copy of fast-xml-parser Rejected: Monkey-patch module.exports.XMLParser | non-configurable getter prevents override Rejected: Object.defineProperty on exports | configurable:false throws TypeError Rejected: Patching fxp.cjs file on disk | fragile, undone by npm install Confidence: high Scope-risk: narrow Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Coverage Report
|
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.
Summary
fast-xml-parserentity expansion limit inwrapper.tsto prevent container deploys from failing withEntity expansion limit exceeded: 1015 > 1000. Container build stacks create enough CloudFormation resources thatDescribeStackEventsXML responses exceed the library's default 1000-entity limit.e2e-helper.tsto handle stacks inROLLBACK_COMPLETE/ROLLBACK_FAILEDstates by deleting them directly via CloudFormation API, with a fallback for normal teardown failures.Root Cause
The
fast-xml-parserv5.x library (used by AWS SDK → CDK toolkit) defaultsmaxTotalExpansionsto 1000. Container builds create ~30+ CloudFormation resources (ECR, KMS, CodeBuild, Lambda custom resource, IAM roles/policies), pushing the XML entity count in API responses over 1000 — especially in CI accounts with accumulated stack event history.Approach
The
fast-xml-parserCJS bundle uses webpack-styleconfigurable: falsegetters on its exports, preventing replacement ofXMLParser. Instead, we patchXMLParser.prototype.parse(which is writable) to raise the limit to 100,000 before every parse call. Therequire()uses a split module name (['fast-xml', 'parser'].join('-')) to prevent esbuild from bundling it, ensuring the patch targets the samenode_modulescopy that@aws-cdk/toolkit-libloads at runtime.Test plan
CREATE_COMPLETE) — previously failed with entity expansion errorRelated
🤖 Generated with Claude Code