golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.74k stars 1.58k forks source link

Unwanted namespacing warning/ or error #1591

Closed mamaart closed 8 months ago

mamaart commented 8 months ago

I originally posted this issue in grpc-go and then here - they told me to post it here instead:

What version of gRPC are you using?

1.59.0

What version of protoc are you using?

libprotoc 25.1

What version of Go are you using (go version)?

1.21.4

What operating system (Linux, Windows, …) and version?

Linux 6.6.4-arch1-1

What did you do?

I have multiple protos defined in a git repo and the generated code is in this repo as well and I use it to import the functionality into the server and clients.

├── events_service │   ├── admin.proto │   ├── golang │   │   ├── admin │   │   │   ├── admin_grpc.pb.go │   │   │   └── admin.pb.go │   │   ├── generate.sh │   │   ├── go.mod │   │   ├── go.sum │   │   ├── shared │   │   │   └── shared.pb.go │   │   └── user │   │   ├── user_grpc.pb.go │   │   └── user.pb.go │   ├── shared.proto │   └── user.proto ├── mailbox_service │   ├── admin.proto │   ├── golang │   │   ├── admin │   │   │   ├── admin_grpc.pb.go │   │   │   └── admin.pb.go │   │   ├── generate.sh │   │   ├── go.mod │   │   └── user │   │   ├── user_grpc.pb.go │   │   └── user.pb.go │   └── user.proto ├── member_service │   ├── admin.proto │   ├── golang │   │   ├── admin │   │   │   ├── admin_grpc.pb.go │   │   │   └── admin.pb.go │   │   ├── generate.sh │   │   ├── go.mod │   │   ├── registration │   │   │   ├── registration_grpc.pb.go │   │   │   └── registration.pb.go │   │   ├── shared │   │   │   └── shared.pb.go │   │   └── statistics │   │   ├── statistics_grpc.pb.go │   │   └── statistics.pb.go │   ├── registration.proto │   ├── shared.proto │   └── statistics.proto └── README.md

They are not related to eachother.

Inside some of them have a protofile called shared (its only used inside the domain and not shared with the others.)

When I have a client application that use all of the protos I get a panic, but I managed to reduce it to a warning after reading the FAQ in the error message.

I have even namespaced the package name in the proto - for instance:

syntax = "proto3";

package eventsservice.shared;

option go_package = "github.com/dk-slack/protos/events_service/golang/shared";

What did you expect to see?

Nothing, no warning and no errors.

What did you see instead?

After running this:

❯ GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn go run ./cmd
WARNING: proto: file "shared.proto" is already registered
    previously from: "github.com/dk-slack/protos/events_service/golang/shared"
    currently from:  "github.com/dk-slack/protos/member_service/golang/shared"
See https://protobuf.dev/reference/go/faq#namespace-conflict

WARNING: proto: file "admin.proto" is already registered
    previously from: "github.com/dk-slack/protos/events_service/golang/admin"
    currently from:  "github.com/dk-slack/protos/member_service/golang/admin"
See https://protobuf.dev/reference/go/faq#namespace-conflict

I've successfully updated all package names for both the Golang files and the general package names to ensure uniqueness. Despite these changes, I've noticed that warnings persist, specifically related to the names of the proto files.

I find this situation a bit puzzling. The reason is that, despite the presence of warnings, the files have been successfully compiled, and the resulting code is fully functional. The warnings appear to be more like artifacts—remnants from an earlier stage of development—rather than genuine indications of a current problem or issue.

puellanivis commented 8 months ago

Closing as a duplicate of https://github.com/golang/protobuf/issues/1122

This warning is not an artifact, and still has relevance. The warning even directs you to the relevant information: https://protobuf.dev/reference/go/faq/#namespace-conflict

While your code appears to be fully functional this is likely because you’ve avoided using any of the code that breaks. There is still a subtle conflict of assumptions that could result in misbehavior in the future. Note from the original thread:

The protoregistry package permits looking up a .proto source file by name. If there are two files with same name and path, it has no way to pick between the them.