aws / aws/jsii

Golang CDK: synth fails when using lazy string due to circular reference

Open
#4,486 3 comments 0 reactions 0 assignees View on GitHub
bug jsii language/dotnet language/go language/python p1 package/tools
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the bug

This is probably specific to the Go CDK bindings, or it is also possible I am misunderstanding the use of the lazy string mechanism. When I try to use the `awscdk.Lazy_String` method for e.g. a log group name, synth fails due to a circular reference:

```
$ CDK_DEBUG=true cdk synth
panic: TypeError: Resolution error: Resolution error: Resolution error: Converting circular structure to JSON
--> starting at object with constructor 'CfnLogGroup'
| property 'node' -> object with constructor 'Node'
--- property 'host' closes the circle.
Object creation stack:
at Lazy.string (/tmp/jsii-kernel-u0LhzS/node_modules/aws-cdk-lib/core/lib/lazy.js:1:953)
at /tmp/jsii-runtime.3237986321/lib/program.js:9876:152
at Kernel._Kernel_ensureSync (/tmp/jsii-runtime.3237986321/lib/program.js:10480:24)
at Kernel.sinvoke (/tmp/jsii-runtime.3237986321/lib/program.js:9876:102)
at KernelHost.processRequest (/tmp/jsii-runtime.3237986321/lib/program.js:11696:36)
at KernelHost.run (/tmp/jsii-runtime.3237986321/lib/program.js:11656:22)
at Immediate._onImmediate (/tmp/jsii-runtime.3237986321/lib/program.js:11657:46)
at process.processImmediate (node:internal/timers:476:21)..
```

See below for a very simple example that reproduces the issue.

### Expected Behavior

Able to use the `awscdk.Lazy_String` function.

### Current Behavior

Synth fails when using the `awscdk.Lazy_String` function.

### Reproduction Steps

Complete example:

```go
package main

import (
"github.com/aws/aws-cdk-go/awscdk/v2"
"github.com/aws/aws-cdk-go/awscdk/v2/awslogs"

"github.com/aws/jsii-runtime-go"
)

type LazyString struct{}

func (l *LazyString) Produce() *string {
s := "value"
return &s
}

func main() {
defer jsii.Close()

app := awscdk.NewApp(nil)
stack := awscdk.NewStack(app, jsii.String("stack"), &awscdk.StackProps{})

lazy := &LazyString{}
awslogs.NewLogGroup(stack, jsii.String("log-group"), &awslogs.LogGroupProps{
LogGroupName: awscdk.Lazy_String(lazy, &awscdk.LazyStringValueOptions{}),
})

app.Synth(nil)
}

```

Then just run cdk synth, and it will fail.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### CDK CLI Version

2.137.0 (build bb90b4c)

### Framework Version

_No response_

### Node.js Version

18.18.2

### OS

Linux

### Language

Go

### Language Version

go version go1.20.12 linux/amd64

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the provided Go example and `cdk synth`. Start by tracing `Lazy.string` in the reported `lazy.js` stack trace through the jsii runtime serialization path in `program.js`; done means the example synthesizes successfully without the circular-structure error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, node.js, typescript
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.