Skip to content

proto: panic: duplicate enum registered: google.protobuf.FieldDescriptorProto_Type #178

Closed
@Globegitter

Description

@Globegitter

I am trying to use custom options in our codebase, as mentioned here: https://developers.google.com/protocol-buffers/docs/proto#customoptions

Our codebase actively supports python, go and java. So protos are built against these three environments. It seems while custom options work fine for java and python there seems to be an issue with go leading to following error message when running code coverage on one of our tests:

2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.FieldMask
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.Timestamp
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.Any
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.FileDescriptorSet
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.FileDescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.DescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.DescriptorProto.ExtensionRange
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.FieldDescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.EnumDescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.EnumValueDescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.ServiceDescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.MethodDescriptorProto
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.FileOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.MessageOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.FieldOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.EnumOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.EnumValueOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.ServiceOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.MethodOptions
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.UninterpretedOption
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.UninterpretedOption.NamePart
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.SourceCodeInfo
2016/04/27 15:33:58 proto: duplicate proto type registered: google.protobuf.SourceCodeInfo.Location
panic: proto: duplicate enum registered: google.protobuf.FieldDescriptorProto_Type

goroutine 1 [running]:
panic(0x8fa960, 0xc8201552d0)
    /usr/lib/go/src/runtime/panic.go:464 +0x3e6
github.com/golang/protobuf/proto.RegisterEnum(0xbbca60, 0x29, 0xc820199980, 0xc8201999b0)
    /path/to/third_party/go/ptypes/src/github.com/golang/protobuf/proto/properties.go:811 +0xe2
third_party/proto/google/protobuf.init.4()
    third_party/proto/google/protobuf/descriptor.pb.go:1913 +0x706
third_party/proto/google/protobuf.init()
    third_party/proto/google/protobuf/descriptor.pb.go:2798 +0x5cd
main.init()
    /path/to/lobby_test_main.go:149 +0x7e

The issue being here we are importing the module third_party/proto/google/protobuf multiple times like so:

import ( 
...
    _cover9 "third_party/proto/google/protobuf"

    _cover10 "third_party/proto/google/protobuf"

    _cover11 "third_party/proto/google/protobuf"

    _cover12 "third_party/proto/google/protobuf"
)

these are being used to set up the coverage before running the actual tests. If I remove these imports and the coverage instrumentation for them all works fine.

So it seems to me that the init function of the descriptor.pb.go is being called multiple times, which in turn registers the enum multiple times and then fails. I don't quite understand how importing the module multiple times can have any effect. If I import our own protos multiple times (that also register enums) everything seems fine.

Is that an issue with the generated code? And is there any way to fix this? (possibly via #131 ?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions