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

Stack overflow panic when schema is recursive #1

Open
jhberges opened this issue Nov 24, 2023 · 1 comment
Open

Stack overflow panic when schema is recursive #1

jhberges opened this issue Nov 24, 2023 · 1 comment

Comments

@jhberges
Copy link

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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/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/topi@v0.0.0-20220626074532-cc7aed7f8c1a/internal/openapi/openapi.go:217 +0xab fp=0xc0a7080c08 sp=0xc0a7080b10 pc=0x7370ab
@lusingander
Copy link
Owner

Yes, I know. Currently, I'm ignoring recursive structures because I have not considered how to handle or display them 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants