简体   繁体   中英

proto: file is already registered with different packages

I have 2 proto compiled under different go packages but when I register them in aa server and run it, I get:

panic: proto: file "common.proto" is already registered
    previously from: "github.com/soft/test-platform.go/common"
    currently from:  "github.com/soft/proto-asterix/asterix"

Here is common.proto in test-platform repository (in /api folder):

syntax = "proto3";
package soft.testplatform.common; // here I do defint a UNIQUE package name !

option java_multiple_files = true;
option go_package = "github.com/soft/test-platform.go/common"; // Here I do define a unique go package name !

message MyMessage{
    string commandId = 1;
}

As you can see, the package definition for go_package and package do not collide with package from github.com/soft/proto-asterix/asterix. Only the.proto filenames are similar (common.proto).

I generate go files with protoc an protoc-gen-go plugin using the following command:

protoc \
--proto_path=../test-platform/api/   \
--go_out=./common --go_opt=paths=source_relative \
../test-platform/api/common.proto

As per documentation here https://developers.google.com/protocol-buffers/docs/reference/go/faq#fix-namespace-conflict the package and filename should be appended to check for a registration conflict but it does not seem to be the case here.

Has anyone encountered such behavior? Do I miss something obvious to resolve this package name collision?


Here is what I tried:

  • Adding/removing package instruction to common.proto file
  • Change protoc command to use an absolute (and not relative) proto_path

Protoc version: libprotoc 3.15.7 Protoc go plugin version: protoc-gen-go v1.26.0

Thanks to @ blackgreen suggestion, indeed, this was a bug fixed by https://go-review.googlesource.com/c/protobuf/+/301953/

While the next release of protoc-gen-go is out, here is a quick fix for your projects:

Use the fixed protoc-gen-go:

go install google.golang.org/protobuf/cmd/protoc-gen-go@febffdd

Change your imports in your go.mod to match

google.golang.org/protobuf v1.26.1-0.20210525005349-febffdd88e85

You should be good to go !

The accepted answer is not correct anymore. This commit reverted the "bugfix" as it was different from other gRPC implementations.

My only way to fix this was to rename the file/folder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM