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

Encoding recursive structs panics since 1.22.0 #227

Closed
molecule-man opened this issue Feb 20, 2024 · 2 comments
Closed

Encoding recursive structs panics since 1.22.0 #227

molecule-man opened this issue Feb 20, 2024 · 2 comments

Comments

@molecule-man
Copy link

package main

import (
	"github.com/guregu/dynamo"
)

func main() {
	type item struct {
		ChildItems []item
	}

	dynamo.MarshalItem(item{})
}

Running this code crashes with panic:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020380318 stack=[0xc020380000, 0xc040380000]
fatal error: stack overflow

runtime stack:
runtime.throw({0x6bcc91?, 0x200000008?})
        /usr/lib/go/src/runtime/panic.go:1077 +0x5c fp=0x7fdd6d1ecca0 sp=0x7fdd6d1ecc70 pc=0x4363dc
runtime.newstack()
        /usr/lib/go/src/runtime/stack.go:1107 +0x5ac fp=0x7fdd6d1ece50 sp=0x7fdd6d1ecca0 pc=0x44fc0c
traceback: unexpected SPWRITE function runtime.morestack
runtime.morestack()
        /usr/lib/go/src/runtime/asm_amd64.s:593 +0x8f fp=0x7fdd6d1ece58 sp=0x7fdd6d1ece50 pc=0x46542f

goroutine 1 [running]:
reflect.(*rtype).NumField(0x68da20?)
        /usr/lib/go/src/reflect/type.go:760 +0x65 fp=0xc020380328 sp=0xc020380320 pc=0x484905
github.com/guregu/dynamo.visitTypeFields({0x9d3480?, 0x68da20?}, 0x0, {0x0, 0x0, 0x0}, 0xc020380608)
...
...
guregu added a commit that referenced this issue May 4, 2024
@guregu
Copy link
Owner

guregu commented May 4, 2024

Hello. Sorry about that. I just released v1.22.2 which should fix this issue. Please give it a try.

@guregu
Copy link
Owner

guregu commented May 5, 2024

v1.22.3 (just released) supports deeper recursion beyond simple self-recursion.
This wacky type works now!

type MegaRecursiveA struct {
	ID      int
	Child   MegaRecursiveB
	Text    string
	Friends []MegaRecursiveA
	Enemies []MegaRecursiveB
}

type MegaRecursiveB struct {
	ID    string
	Child *MegaRecursiveA
	Blah  int `dynamo:",omitempty"`
}

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