topi icon indicating copy to clipboard operation
topi copied to clipboard

Stack overflow panic when schema is recursive

Open jhberges opened this issue 9 months ago • 1 comments

Greetings! Nice idea, this!

A little snag I've discovered, via an in-house OAS. This OAS bleeds database complexity, including a recursive graph (in effect a double linked parent-child relationship). The complexity should not really be exposed in the OAS, but it got out - so I'm guessing it's not a especially unique blunder :-D

If the schema contains something like the following, the app will panic with stack overflow (excerpt below).

Mocked up example schema:

components:
   schemas:
      Parent:
         required:
            - children
         type: object
         properties:
            children:
               type: array
               items:
                  $ref: '#/components/schemas/Child'
      Child:
         required:
            - parent
         type: object
         properties:
            parent:
               $ref: '#/components/schemas/Parent'

Error excerpt:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc0a7080388 stack=[0xc0a7080000, 0xc0c7080000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xdfc9a3?, 0x7f80fd8e6cf0?})
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/panic.go:1077 +0x5c fp=0x7f80fd8e6ca0 sp=0x7f80fd8e6c70 pc=0x43a99c
runtime.newstack()
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/stack.go:1107 +0x5ac fp=0x7f80fd8e6e50 sp=0x7f80fd8e6ca0 pc=0x45464c
traceback: unexpected SPWRITE function runtime.morestack
runtime.morestack()
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/asm_amd64.s:593 +0x8f fp=0x7f80fd8e6e58 sp=0x7f80fd8e6e50 pc=0x46b40f

goroutine 1 [running]:
runtime.deductAssistCredit(0x30?)
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/malloc.go:1271 +0x70 fp=0xc0a7080398 sp=0xc0a7080390 pc=0x411f30
runtime.mallocgc(0x30, 0xd9a0a0, 0x1)
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/malloc.go:1002 +0xc9 fp=0xc0a7080400 sp=0xc0a7080398 pc=0x411749
runtime.newobject(0x0?)
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/malloc.go:1324 +0x25 fp=0xc0a7080428 sp=0xc0a7080400 pc=0x412005
runtime.makemap_small()
	/home/jhb/.asdf/installs/golang/1.21.3/go/src/runtime/map.go:295 +0x1a fp=0xc0a7080448 sp=0xc0a7080428 pc=0x412a5a
github.com/lusingander/topi/internal/openapi.convertSchemas(...)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:224
github.com/lusingander/topi/internal/openapi.convertSchema(0x0?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:219 +0xc9 fp=0xc0a7080540 sp=0xc0a7080448 pc=0x7370c9
github.com/lusingander/topi/internal/openapi.convertSchema(0xc0a70806c0?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:217 +0xab fp=0xc0a7080638 sp=0xc0a7080540 pc=0x7370ab
github.com/lusingander/topi/internal/openapi.convertSchemas(...)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:226
github.com/lusingander/topi/internal/openapi.convertSchema(0x0?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:219 +0x157 fp=0xc0a7080730 sp=0xc0a7080638 pc=0x737157
github.com/lusingander/topi/internal/openapi.convertSchemas(...)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:226
github.com/lusingander/topi/internal/openapi.convertSchema(0x0?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:219 +0x157 fp=0xc0a7080828 sp=0xc0a7080730 pc=0x737157
github.com/lusingander/topi/internal/openapi.convertSchema(0xc0a70809a8?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:217 +0xab fp=0xc0a7080920 sp=0xc0a7080828 pc=0x7370ab
github.com/lusingander/topi/internal/openapi.convertSchemas(...)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:226
github.com/lusingander/topi/internal/openapi.convertSchema(0xc0a7080aa0?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:219 +0x157 fp=0xc0a7080a18 sp=0xc0a7080920 pc=0x737157
github.com/lusingander/topi/internal/openapi.convertSchemas(...)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:226
github.com/lusingander/topi/internal/openapi.convertSchema(0x0?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:219 +0x157 fp=0xc0a7080b10 sp=0xc0a7080a18 pc=0x737157
github.com/lusingander/topi/internal/openapi.convertSchema(0xc0a7080c90?)
	/home/jhb/.asdf/installs/golang/1.21.3/packages/pkg/mod/github.com/lusingander/[email protected]/internal/openapi/openapi.go:217 +0xab fp=0xc0a7080c08 sp=0xc0a7080b10 pc=0x7370ab

jhberges avatar Nov 24 '23 12:11 jhberges