awslabs / diagram-as-code

Diagram-as-code for AWS architecture.
Apache License 2.0
406 stars 23 forks source link

Prevent circular references #35

Open ugwis opened 2 months ago

ugwis commented 2 months ago

why

There is no mechanism to detect circular references, so incorrect references will cause stack overflows.

$ cat rec.yaml               
Diagram:
  Resources:
    Canvas:
      Type: AWS::Diagram::Canvas
      Direction: vertical
      Children:
        - Resource1
    Resource1:
      Type: AWS::Diagram::Group
      Children:
        - Resource2
    Resource2:
      Type: AWS::Diagram::Group
      Children:
        - Resource1
$ awsdac rec.yaml -v
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc0201e0390 stack=[0xc0201e0000, 0xc0401e0000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xd4bf112?, 0x200000001?})
    /usr/local/Cellar/go/1.22.0/libexec/src/runtime/panic.go:1023 +0x5c fp=0x700009667d88 sp=0x700009667d58 pc=0xd23489c
runtime.newstack()
    /usr/local/Cellar/go/1.22.0/libexec/src/runtime/stack.go:1103 +0x5bd fp=0x700009667f38 sp=0x700009667d88 pc=0xd24fb5d
runtime.morestack()
    /usr/local/Cellar/go/1.22.0/libexec/src/runtime/asm_amd64.s:616 +0x7a fp=0x700009667f40 sp=0x700009667f38 pc=0xd2678fa

goroutine 1 gp=0xc000006380 m=4 mp=0xc000057b08 [running]:
runtime.convTstring({0x0?, 0x0?})
    /usr/local/Cellar/go/1.22.0/libexec/src/runtime/iface.go:388 +0x8c fp=0xc0201e03a0 sp=0xc0201e0398 pc=0xd20936c
github.com/awslabs/diagram-as-code/internal/types.(*Group).Scale(0xc0000ee500)

what

Detect and warn about circular resource references