protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

proto: return an error for cycles in protobuf messages

Open Mido-sys opened this issue 3 years ago • 8 comments

What version of protobuf and what language are you using? Version: libprotoc 3.15.3 Go: 1.16

What did you do?

To generate the go proto protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative bug/bug.proto

Create a subfolder. For example folder/folder1/a.css

bug.proto

syntax = 'proto3';

package bug;

option go_package = "github.com//mido-sys/proto/bug";

message FileInfo{
    
   string name =1;
   uint64 size = 2;
   uint64 mode_time =3;
   bool is_dir =4;
   
}

message Node{
    string full_path =1;
    FileInfo info =2;
    repeated Node children =3;
    Node Parent =4;
    
}

go.mod:

go 1.16

require (
	github.com/golang/protobuf v1.4.3
	google.golang.org/protobuf v1.25.0
)

Go code:

package main

import (
	//"fmt"

	"encoding/json"
	"log"
	"os"
	"path/filepath"

	"bitbucket.org/numinix/grpc_bug/bug"
)

// FileInfo is a struct created from os.FileInfo interface for serialization.
type FileInfo struct {
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	ModTime int64  `json:"mod_time"`
	IsDir   bool   `json:"is_dir"`
}

// Node represents a node in a directory tree.
type Node struct {
	FullPath string    `json:"path"`
	Info     *FileInfo `json:"info"`
	Children []*Node   `json:"children"`
	Parent   *Node     `json:"-"`
}

// Helper function to create a local FileInfo struct from os.FileInfo interface.
func fileInfoFromInterfaceJSON(v os.FileInfo) *FileInfo {
	return &FileInfo{v.Name(), v.Size(), v.ModTime().Unix(), v.IsDir()}
}

// Create directory hierarchy.
func NewTreeJson(root string) (result *Node, err error) {
	absRoot, err := filepath.Abs(root)
	if err != nil {
		return
	}
	parents := make(map[string]*Node)
	walkFunc := func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		parents[path] = &Node{
			FullPath: path,
			Info:     fileInfoFromInterfaceJSON(info),
			Children: make([]*Node, 0),
		}
		return nil
	}
	if err = filepath.Walk(absRoot, walkFunc); err != nil {
		return
	}
	for path, node := range parents {
		parentPath := filepath.Dir(path)
		parent, exists := parents[parentPath]
		if !exists { // If a parent does not exist, this is the root.
			result = node
		} else {
			node.Parent = parent
			parent.Children = append(parent.Children, node)
		}
	}
	return
}

// Helper function to create a local FileInfo struct from os.FileInfo interface.
func fileInfoFromInterfaceGRPC(v os.FileInfo) *bug.FileInfo {
	return &bug.FileInfo{
		Name:     v.Name(),
		Size:     uint64(v.Size()),
		ModeTime: uint64(v.ModTime().Unix()),
		IsDir:    v.IsDir(),
	}
}

// Create directory hierarchy.
func NewTreeGRPC(root string) (result *bug.Node, err error) {
	absRoot, err := filepath.Abs(root)
	if err != nil {
		return
	}
	parents := make(map[string]*bug.Node)
	walkFunc := func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		parents[path] = &bug.Node{
			FullPath: path,
			Info:     fileInfoFromInterfaceGRPC(info),
			Children: make([]*bug.Node, 0),
		}
		return nil
	}
	if err = filepath.Walk(absRoot, walkFunc); err != nil {
		return
	}
	for path, node := range parents {
		parentPath := filepath.Dir(path)
		parent, exists := parents[parentPath]
		if !exists { // If a parent does not exist, this is the root.
			result = node
		} else {
			node.Parent = parent
			parent.Children = append(parent.Children, node)
		}
	}
	return
}
func main() {
	jsonF := false
	if jsonF {

		aa, _ := NewTreeJson("./templates")
		vv, _ := json.Marshal(aa)
		log.Println(string(vv))
	} else {

		aa, _ := NewTreeGRPC("./templates")
		log.Println(aa)
	}
}


What did you expect to see?

Not to panic

What did you see instead?

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020280418 stack=[0xc020280000, 0xc040280000]
fatal error: stack overflow

runtime stack:
runtime.throw(0x610aaa, 0xe)
        /usr/local/go/src/runtime/panic.go:1117 +0x72
runtime.newstack()
        /usr/local/go/src/runtime/stack.go:1069 +0x7ed
runtime.morestack()
        /usr/local/go/src/runtime/asm_amd64.s:458 +0x8f

goroutine 1 [running]:
google.golang.org/protobuf/internal/impl.(*MessageInfo).checkField(0xc00010c500, 0x650f30, 0xc000073500, 0x40b52a, 0x5da260, 0x606a00)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/internal/impl/message_reflect.go:332 +0x951 fp=0xc020280428 sp=0xc020280420 pc=0x59a951
google.golang.org/protobuf/internal/impl.(*messageState).Has(0xc000062190, 0x650f30, 0xc000073500, 0xc000073500)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/internal/impl/message_reflect_gen.go:66 +0x68 fp=0xc020280478 sp=0xc020280428 pc=0x59e048
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000062190, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:184 +0x3f5 fp=0xc0202805c8 sp=0xc020280478 pc=0x51a595
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000062190, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202806d0 sp=0xc0202805c8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016927, 0x4, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020280788 sp=0xc0202806d0 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc0202808d8 sp=0xc020280788 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202809e0 sp=0xc0202808d8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020280aa0 sp=0xc0202809e0 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020280b58 sp=0xc020280aa0 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020280ca8 sp=0xc020280b58 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020280db0 sp=0xc020280ca8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020280e68 sp=0xc020280db0 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020280fb8 sp=0xc020280e68 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202810c0 sp=0xc020280fb8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020281180 sp=0xc0202810c0 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020281238 sp=0xc020281180 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020281388 sp=0xc020281238 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020281490 sp=0xc020281388 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020281548 sp=0xc020281490 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020281698 sp=0xc020281548 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202817a0 sp=0xc020281698 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020281860 sp=0xc0202817a0 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020281918 sp=0xc020281860 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020281a68 sp=0xc020281918 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020281b70 sp=0xc020281a68 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020281c28 sp=0xc020281b70 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020281d78 sp=0xc020281c28 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020281e80 sp=0xc020281d78 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020281f40 sp=0xc020281e80 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020281ff8 sp=0xc020281f40 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020282148 sp=0xc020281ff8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020282250 sp=0xc020282148 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020282308 sp=0xc020282250 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020282458 sp=0xc020282308 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020282560 sp=0xc020282458 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020282620 sp=0xc020282560 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc0202826d8 sp=0xc020282620 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020282828 sp=0xc0202826d8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020282930 sp=0xc020282828 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc0202829e8 sp=0xc020282930 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020282b38 sp=0xc0202829e8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020282c40 sp=0xc020282b38 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020282d00 sp=0xc020282c40 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020282db8 sp=0xc020282d00 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020282f08 sp=0xc020282db8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020283010 sp=0xc020282f08 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc0202830c8 sp=0xc020283010 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020283218 sp=0xc0202830c8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020283320 sp=0xc020283218 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc0202833e0 sp=0xc020283320 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020283498 sp=0xc0202833e0 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc0202835e8 sp=0xc020283498 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202836f0 sp=0xc0202835e8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc0202837a8 sp=0xc0202836f0 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc0202838f8 sp=0xc0202837a8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020283a00 sp=0xc0202838f8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020283ac0 sp=0xc020283a00 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020283b78 sp=0xc020283ac0 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020283cc8 sp=0xc020283b78 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020283dd0 sp=0xc020283cc8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020283e88 sp=0xc020283dd0 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020283fd8 sp=0xc020283e88 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202840e0 sp=0xc020283fd8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc0202841a0 sp=0xc0202840e0 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020284258 sp=0xc0202841a0 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc0202843a8 sp=0xc020284258 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202844b0 sp=0xc0202843a8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020284568 sp=0xc0202844b0 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc0202846b8 sp=0xc020284568 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc0202847c0 sp=0xc0202846b8 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020284880 sp=0xc0202847c0 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020284938 sp=0xc020284880 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020284a88 sp=0xc020284938 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020284b90 sp=0xc020284a88 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020284c48 sp=0xc020284b90 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020284d98 sp=0xc020284c48 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020284ea0 sp=0xc020284d98 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020284f60 sp=0xc020284ea0 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020285018 sp=0xc020284f60 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020285168 sp=0xc020285018 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020285270 sp=0xc020285168 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020285328 sp=0xc020285270 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020285478 sp=0xc020285328 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020285580 sp=0xc020285478 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020285640 sp=0xc020285580 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc0202856f8 sp=0xc020285640 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020285848 sp=0xc0202856f8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020285950 sp=0xc020285848 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc020285a08 sp=0xc020285950 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020285b58 sp=0xc020285a08 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020285c60 sp=0xc020285b58 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020285d20 sp=0xc020285c60 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc020285dd8 sp=0xc020285d20 pc=0x51aee5
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058360, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020285f28 sp=0xc020285dd8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058360, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020286030 sp=0xc020285f28 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016985, 0x6, 0x604560, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:221 +0x1ee fp=0xc0202860e8 sp=0xc020286030 pc=0x51ac6e
google.golang.org/protobuf/encoding/prototext.encoder.marshalMessage(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x650420, 0xc000058420, 0xc000058401, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:194 +0x325 fp=0xc020286238 sp=0xc0202860e8 pc=0x51a4c5
google.golang.org/protobuf/encoding/prototext.encoder.marshalSingular(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0x604560, 0xc000058420, 0x0, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:270 +0x4bb fp=0xc020286340 sp=0xc020286238 pc=0x51b3db
google.golang.org/protobuf/encoding/prototext.encoder.marshalList(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x64f878, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:283 +0x1fc fp=0xc020286400 sp=0xc020286340 pc=0x51bb1c
google.golang.org/protobuf/encoding/prototext.encoder.marshalField(0xc000058480, 0x0, 0x0, 0x0, 0x1010100, 0x64e7e0, 0xc00006c150, 0xc000016954, 0x8, 0x5f7a40, ...)
        /home/mido/go/pkg/mod/google.golang.org/[email protected]/encoding/prototext/encode.go:216 +0x465 fp=0xc0202864b8 sp=0xc020286400 pc=0x51aee5

Anything else we should know about your project/environment?

The code creates a directory tree of the target folder. I added the JSON version of the code to confirm that the bug isn't in the code logic. To use the GRPC, set the JsonF to false.

Disclaimer: I'm not the original author of the JSON code.

Mido-sys avatar Feb 26 '21 23:02 Mido-sys

I'm afraid protobufs don't support cyclic data structures.

Ideally we'd return an error rather than panicking if the recursion depth grows too large, but the fundamental problem you're encountering here is that you must not create reference cycles within a protobuf message.

neild avatar Feb 27 '21 00:02 neild

As @neild said, protocol buffers do not support cyclic data structures.

I'm not sure there's much we can do here. Detecting cycles is expensive, so we can't enable it by default. We could start detecting cycles at a certain depth, but there are several problems with even that:

  1. At what depth? People do serialize extremely large protobufs and we don't want to hinder those cases.
  2. The API where the marshal logic for one message calls the marshal logic for another message does not plumb down the current depth nor any data structure for what pointers have been seen so far.

dsnet avatar Feb 27 '21 01:02 dsnet

Thanks for the clarification, @neild & @dsnet.

The encoding/json package returns an error json: unsupported value: encountered a cycle via Node if we try to marshal the Parent. So maybe follow the same depth as the encoding/json package?

Mido-sys avatar Feb 27 '21 01:02 Mido-sys

As the maintainer of the encoding/json package, I would argue that the depth used there is too low for protobuf, which tends to serialize much larger datasets. Secondly, the check there does not actually work across nested MarshalJSON call.

dsnet avatar Feb 27 '21 01:02 dsnet

FWIW, I think the standard protobuf recursion depth limit in other implementations is 100, adjustable via options. We really should have a recursion depth check to produce an error rather than a stack overflow.

neild avatar Feb 27 '21 04:02 neild

I’m going to agree with neild, we should hopefully support some form of cycle detection. It doesn’t really make sense to wait for the go runtime to panic recursing through values that we already know will end up in a stack-too-big panic.

puellanivis avatar Feb 27 '21 09:02 puellanivis

Cycle detection can be expensive, but simple depth detection (levels of subfields) is not expensive and is easier.

I'm not familiar with the other language implementations, and I can't seem to find such options in their docs.

cybrcodr avatar Feb 27 '21 10:02 cybrcodr

C++ binary serialization API recursion limit: https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.io.coded_stream#recursion-limit

I'm not sure about the state of recursion limits for text/JSON serialization.

neild avatar Mar 01 '21 08:03 neild