[Bug?] Repeated imported enum cause panic in golang

17 views
Skip to first unread message

Jing Lv

unread,
May 22, 2020, 10:21:20 AM5/22/20
to Protocol Buffers

Hello,


    I've got a wired issue working with protobuf/golang. I have a proto defined a enum like

enum OSType {

    UNKNOWN_OSTYPE = 0;

    MACOS          = 1;

    IOS            = 2;

    ANDROID        = 3;

    WINDOWS        = 4;

}

in fileA,  then import it and use it in a object in fileB


import fileA

...

message SomeObj {

    ... 

    repeated OSType platforms = 10;

    ...

}


    then generate into some go files. When I use it as a return value of, I find the panic, whatever I put a nil, empty array, or an array of several OSTypes(non-duplicated).

    Debug into the code and find it's related to this enum array - in this object I have several other enums but none of them cause any problem. What's more, if I move this enum array out of FileA, the panic disappeared immediately.

    The panic reads like[1]. Also I'm using Kite framework, not sure if it is related.


    I am not sure if this is a mis-use or bug? Though I've got a workaround, looking forwards some insight and best-practice. Thanks.


[1]

[2020-05-22T21:03:55+08:00] catch panic!!! panic location: google.golang.org/protobuf/internal/filedesc.(*EnumValues).Get:66

stacktrace:

goroutine 4447 [running]:

runtime/debug.Stack(0xc001836528, 0x31e87a0, 0xc000456c30)

        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d

git.purefire.org/package/common.Recover(0x3267540, 0xc001d580c0, 0xc000c6c9c8)

        /Users/purefire/go/pkg/mod/git.purefire.org/package/com...@v1.0.322/common.go:213 +0x16e

panic(0x2b9ec00, 0xc0008ab7c0)

        /usr/local/go/src/runtime/panic.go:679 +0x1b2

google.golang.org/protobuf/internal/filedesc.(*EnumValues).Get(0xc0000f01c0, 0x0, 0xc0000f01c0, 0x101008b)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/filedesc/desc_list_gen.go:66 +0x4b

google.golang.org/protobuf/internal/impl.newEnumConverter(0x32859e0, 0x2a2c6a0, 0x32858c0, 0xc000264d60, 0x29bb7c0, 0xc0018993e0)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/convert.go:379 +0x85

google.golang.org/protobuf/internal/impl.newSingularConverter(0x32859e0, 0x2a2c6a0, 0x32858c0, 0xc000264d60, 0xc000c6bb60, 0x116987b)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/convert.go:138 +0xefa

google.golang.org/protobuf/internal/impl.newListConverter(0x32859e0, 0xc0001e8ac0, 0x32858c0, 0xc000264d60, 0xe0, 0x2b12f60)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/convert_list.go:17 +0xae

google.golang.org/protobuf/internal/impl.NewConverter(0x32859e0, 0xc0001e8ac0, 0x32858c0, 0xc000264d60, 0xc000c6bc18, 0x1016587)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/convert.go:56 +0x123

google.golang.org/protobuf/internal/impl.fieldInfoForList(0x32858c0, 0xc000264d60, 0x29f3e60, 0x9, 0x0, 0x0, 0x32859e0, 0x290fa00, 0x29f3e6b, 0x4e, ...)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/message_reflect_field.go:172 +0xe1

google.golang.org/protobuf/internal/impl.(*MessageInfo).makeKnownFieldsFunc(0xc000d9a140, 0xffffffffffffffff, 0xffffffffffffffff, 0x80, 0xffffffffffffffff, 0xc001fb7ad0, 0xc001fb7b00, 0xc001fb7b30, 0xc001fb7b60)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/message_reflect.go:61 +0x673

google.golang.org/protobuf/internal/impl.(*MessageInfo).makeReflectFuncs(0xc000d9a140, 0x32859e0, 0x2d16600, 0xffffffffffffffff, 0xffffffffffffffff, 0x80, 0xffffffffffffffff, 0xc001fb7ad0, 0xc001fb7b00, 0xc001fb7b30, ...)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/message_reflect.go:36 +0x63

google.golang.org/protobuf/internal/impl.(*MessageInfo).initOnce(0xc000d9a140)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/message.go:90 +0x19c

google.golang.org/protobuf/internal/impl.(*MessageInfo).init(0xc000d9a140)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/message.go:72 +0x3c

google.golang.org/protobuf/internal/impl.(*messageReflectWrapper).ProtoMethods(0xc0004563d0, 0x120804b)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/message_reflect_gen.go:150 +0x2f

google.golang.org/protobuf/proto.protoMethods(...)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/proto/proto_methods.go:18

google.golang.org/protobuf/proto.sizeMessage(0x327da60, 0xc0004563d0, 0xc0004563d0)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/proto/size.go:30 +0x35

google.golang.org/protobuf/proto.MarshalOptions.Size(0x2000000, 0x31e9c80, 0xc0004563d0, 0x31e9c80)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/proto/size.go:26 +0x4e

google.golang.org/protobuf/proto.Size(...)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/proto/size.go:16

google.golang.org/protobuf/internal/impl.sizeMessageSlice(0xc001fb7a70, 0x32859e0, 0x2cbdf40, 0x1, 0x2d43700, 0x2ad9e00)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/codec_field.go:526 +0xbb

google.golang.org/protobuf/internal/impl.makeMessageSliceFieldCoder.func1(0xc001fb7a70, 0xc00191ac60, 0x2e4800, 0x2ad9e00)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/codec_field.go:452 +0x54

google.golang.org/protobuf/internal/impl.(*MessageInfo).sizePointerSlow(0xc000d9a3c0, 0xc001fb7a70, 0x5054d00, 0x0)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/encode.go:79 +0xbe

google.golang.org/protobuf/internal/impl.(*MessageInfo).sizePointer(0xc000d9a3c0, 0xc001fb7a70, 0x2ad9e00, 0xc001fb7a70)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/encode.go:56 +0x7

google.golang.org/protobuf/internal/impl.(*MessageInfo).size(0xc000d9a3c0, 0x327da60, 0xc000456380, 0x1208100, 0xc000d9a3c0)

       /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/internal/impl/encode.go:40 +0x55

google.golang.org/protobuf/proto.MarshalOptions.marshal(0xc000000001, 0x0, 0x0, 0x0, 0x327da60, 0xc000456380, 0xc000456380, 0x327da60, 0xc000456380, 0x2ad9e00, ...)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/proto/encode.go:153 +0x2f6

google.golang.org/protobuf/proto.MarshalOptions.MarshalAppend(0x2000001, 0x0, 0x0, 0x0, 0x31e9c80, 0xc000456380, 0x29dfa40, 0x300db40, 0x2a934e0, 0xc0023eb260, ...)

        /Users/purefire/go/pkg/mod/google.golang.org/prot...@v1.23.0/proto/encode.go:125 +0x98

github.com/golang/protobuf/proto.marshalAppend(0x0, 0x0, 0x0, 0x324fa80, 0xc001fb7a70, 0x324fa00, 0xc001fb7a70, 0x0, 0x0, 0x0, ...)

        /Users/purefire/go/pkg/mod/github.com/golang/prot...@v1.4.2/proto/wire.go:40 +0xbe

github.com/golang/protobuf/proto.Marshal(...)

        /Users/purefire/go/pkg/mod/github.com/golang/prot...@v1.4.2/proto/wire.go:23

...


Joe Tsai

unread,
May 23, 2020, 2:11:20 PM5/23/20
to Protocol Buffers
Hi. At first glance at the stack trace, this does not seem to be an expected panic. Could you file a bug at on the issue tracker with a minimum reproduction so that we can investigate? Thanks. https://github.com/golang/protobuf

JT.

Jing Lv

unread,
May 23, 2020, 10:02:14 PM5/23/20
to Protocol Buffers
Thanks JT, I create one in https://github.com/golang/protobuf/issues/1135 

在 2020年5月24日星期日 UTC+8上午2:11:20,Joe Tsai写道:
Reply all
Reply to author
Forward
0 new messages