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

aws-cdk-lib/core: RangeError: Map maximum size exceeded #29785

Closed
gockle opened this issue Apr 10, 2024 · 8 comments
Closed

aws-cdk-lib/core: RangeError: Map maximum size exceeded #29785

gockle opened this issue Apr 10, 2024 · 8 comments
Labels
bug This issue is a bug. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@gockle
Copy link

gockle commented Apr 10, 2024

Describe the bug

When I am trying to do npx cdk synth in the project Serverless-Image-Handler, I am getting an error.

Expected Behavior

The command npx cdk synth should output a CloudFormation Template.

Current Behavior

Getting an error

RangeError: Map maximum size exceeded
    at Map.set (<anonymous>)
    at TokenMap.registerStringKey ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/aws-cdk-lib/core/lib/private/token-map.js:1:2399)
    at [PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/aws-cdk-lib/core/lib/private/token-map.js:1:754
    at cachedValue ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/aws-cdk-lib/core/lib/private/token-map.js:1:2725)
    at TokenMap.registerString ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/aws-cdk-lib/core/lib/private/token-map.js:1:702)
    at Function.asString ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/aws-cdk-lib/core/lib/token.js:1:1541)
    at PolicyStatement.toString ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/aws-cdk-lib/aws-iam/lib/policy-statement.js:2:6884)
    at realTypeOf ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/@aws-solutions-constructs/core/node_modules/deep-diff/index.js:117:81)
    at deepDiff ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/@aws-solutions-constructs/core/node_modules/deep-diff/index.js:213:36)
    at deepDiff ([PATH_TO_REPO]/Serverless-image-handler/source/constructs/node_modules/@aws-solutions-constructs/core/node_modules/deep-diff/index.js:246:13)

Reproduction Steps

git clone [email protected]:aws-solutions/serverless-image-handler.git
cd serverless-image-handler/source && npm i
cd image-handler && npm i
cd ../custom-resource/ && npm i
cd ../constructs/ && npm i
NODE_OPTIONS=--max-old-space-size=8192
npx cdk synth

Possible Solution

The issue does not show up if the environment variable overrideWarningsEnabled is set to false

Command: overrideWarningsEnabled=false npx cdk synth

Additional Information/Context

No response

CDK CLI Version

2.102.0

Framework Version

No response

Node.js Version

v18.18.1

OS

MacOS 14.4.1 (23E224)

Language

TypeScript

Language Version

5.2.2

Other information

Similar bug here #21062

@gockle gockle added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2024
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Apr 10, 2024
@khushail
Copy link
Contributor

Hi @gockle , the project (aws-solutions/serverles-image-handler))you linked is not CDK related or not handled by CDK Team. The issue linked #21062 is also not owned by CDK Team as you can read in the comments.

It would be helpful if you could share more insights into why this relates to CDK.

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 10, 2024
@gockle
Copy link
Author

gockle commented Apr 10, 2024

Hi Khushail

the stack trace indicates the source of the issue is in the function registerStringKey in the file TokenMap forPolicyStatement.toString here

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Apr 10, 2024
@scanlonp scanlonp added p1 p2 and removed p1 labels Apr 22, 2024
@scanlonp
Copy link
Contributor

Hey @gockle, looking at the comments on the bug you linked, it appears the underlying problem was with the aws-solution-constructs. Any reason you believe this issue is different; that it is related to the CDK library code rather than the construct?

@gockle
Copy link
Author

gockle commented Apr 22, 2024

Hi @scanlonp aws-solutions-construct uses the node-module deep-diff here to provide override information, the issue is when the module deep-diff is calling to string on iam policy resource. The exact function call from deep-diff is here. When deep-diff calls toString, the aws-cdk code fails in token-maps.ts,

I am not sure why the bug #21062 stopped and assumed its an issue with the aws-solutions-construct. on first review the comment below, is same as what we are facing.

I can deploy the same stack to a different account fine. The stack we have could not potentially be creating 2^24 entities/things in PolicyStatement, otherwise it would have failed to deploy to the other account.
Something is happening in PolicyStatement.toString which probably making it go into an infinite loop.

@gockle
Copy link
Author

gockle commented Apr 22, 2024

The token-map documentation clearly states that TokenStringMap storage is shared so this doesn't look like a cdk issue.

/**
 * Central place where we keep a mapping from Tokens to their String representation
 *
 * The string representation is used to embed token into strings,
 * and stored to be able to reverse that mapping.
 *
 * All instances of TokenStringMap share the same storage, so that this process
 * works even when different copies of the library are loaded.
 */

Closing this issue.

@gockle gockle closed this as completed Apr 22, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@scanlonp
Copy link
Contributor

@gockle, got it, thank you! If you do find what is causing this, feel free commenting here (even through the visibility warning); I would be interested in case we see this in the future!

@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

4 participants