aws / aws/aws-cdk

core: Stack with many resources combined with aspects results in StackOverflowErrors

Open
#26,517 7 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/core bug effort/large jsii p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

When using aspects in combination with stacks with a large number of resources we are running into StackOverflowError during synthesis in our Java CDK applications. The issue is somewhat system dependent as the default limits enforced by the JVM change depending on available system resources (and probably JVM vendor).

### Expected Behavior

Stacks with many resources with aspects to synthesize successfully.

### Current Behavior

Synthesis fails on a StackOverFlowError.

### Reproduction Steps

I have managed to reproduce the issue in a minimal project, available here: [https://github.com/Saberos/cdk-aspect-stackoverflowerror](https://github.com/Saberos/cdk-aspect-stackoverflowerror)

`cdk synth` produces the error while the aspect is present. Once the aspect is removed synthesis completes as expected. Note that the stack size has been forcibly limited in the `cdk.json` to ensure the issue is reproducible independent of the system. Without the `-Xss` flag the issue may or may not appear on the system. Increasing the number of resources in the stack or the number of aspects should allow the issue to be reproduced on any system even without using this flag.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.86.0

### Framework Version

2.86.0

### Node.js Version

v18.12.1

### OS

macOS Ventura 13.2.1

### Language

Java

### Language Version

Corretto-17.0.7.7.1

### Other information

The StackOverflowError stacktrace:
```
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project cdk-aspect-stackoverflowerror: An exception occured while executing the Java class. null
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:347)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: An exception occured while executing the Java class. null
at org.codehaus.mojo.exec.ExecJavaMojo.execute (ExecJavaMojo.java:311)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:910)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.lang.StackOverflowError
at com.fasterxml.jackson.databind.node.NodeCursor$ObjectCursor.currentNode (NodeCursor.java:224)
at com.fasterxml.jackson.databind.node.TreeTraversingParser.currentNode (TreeTraversingParser.java:374)
at com.fasterxml.jackson.databind.node.TreeTraversingParser.getText (TreeTraversingParser.java:205)
at com.fasterxml.jackson.databind.deser.std.BaseNodeDeserializer._deserializeAnyScalar (JsonNodeDeserializer.java:564)
at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize (JsonNodeDeserializer.java:93)
at com.fasterxml.jackson.databind.deser.std.JsonNodeDeserializer.deserialize (JsonNodeDeserializer.java:20)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue (DefaultDeserializationContext.java:323)
at com.fasterxml.jackson.databind.ObjectMapper._readValue (ObjectMapper.java:4650)
at com.fasterxml.jackson.databind.ObjectMapper.readTree (ObjectMapper.java:2941)
at com.fasterxml.jackson.core.JsonParser.readValueAsTree (JsonParser.java:2365)
at software.amazon.jsii.JsiiObjectMapper$JsiiDeserializer.deserialize (JsiiObjectMapper.java:130)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet (MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize (BeanDeserializer.java:314)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize (BeanDeserializer.java:177)
at software.amazon.jsii.JsiiObjectMapper$JsiiDeserializer.deserialize (JsiiObjectMapper.java:149)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet (MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize (BeanDeserializer.java:314)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize (BeanDeserializer.java:177)
at software.amazon.jsii.JsiiObjectMapper$JsiiDeserializer.deserialize (JsiiObjectMapper.java:149)
at com.fasterxml.jackson.databind.ObjectMapper._convert (ObjectMapper.java:4388)
at com.fasterxml.jackson.databind.ObjectMapper.convertValue (ObjectMapper.java:4344)
at software.amazon.jsii.JsiiObjectMapper.treeToValue (JsiiObjectMapper.java:46)
at software.amazon.jsii.JsiiRuntime.processCallbackResponse (JsiiRuntime.java:165)
at software.amazon.jsii.JsiiRuntime.requestResponse (JsiiRuntime.java:121)
at software.amazon.jsii.JsiiRuntime.processCallbackResponse (JsiiRuntime.java:197)
... Above 2 lines repeating many times
at software.amazon.jsii.JsiiRuntime.processCallbackResponse (JsiiRuntime.java:197)
at software.amazon.jsii.JsiiRuntime.requestResponse (JsiiRuntime.java:121)
at software.amazon.jsii.JsiiClient.callMethod (JsiiClient.java:184)
at software.amazon.jsii.Kernel.call (Kernel.java:52)
at software.amazon.awscdk.Stage.synth (Stage.java:109)
at com.myorg.CdkAspectStackoverflowerrorApp.main (CdkAspectStackoverflowerrorApp.java:19)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
at java.lang.Thread.run (Thread.java:833)
```

Contributor guide

Open the contributing guide

Research direction

Start with the linked minimal project and run `cdk synth` using the constrained `-Xss` setting to reproduce the failure. Trace the repeated jsii callback path in the stack trace from `Stage.synth` through `JsiiRuntime.processCallbackResponse`; done means stacks with many resources and aspects synthesize without `StackOverflowError`, ideally with a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.