golang / protobuf

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

Is there any other problem with converting “namespace conflict” panic to warning? #1498

Closed FGYFFFF closed 1 year ago

FGYFFFF commented 1 year ago

Hi ~ I have a go project that uses protobuf generated content locally, and the dependencies for that project use the same protobuf generated content. So I had the problem of namespce conflict, and I saw from the official documentation that I could add a compile option to turn this panic into a warning. My project only uses go structs generated by protobuf, and does not make rpc calls. So I would like to ask if there are any other side effects when namespace conflict is converted to warnning.

Translated with www.DeepL.com/Translator (free version)

aktau commented 1 year ago

What option did you pass (and to what) to turn the panic into a warning? I'm not (yet) familiar with this functionality and would need to look into it. Thanks!

FGYFFFF commented 1 year ago

What option did you pass (and to what) to turn the panic into a warning? I'm not (yet) familiar with this functionality and would need to look into it. Thanks!

https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict

Starting with v1.26.0 of the google.golang.org/protobuf module, a hard error will be reported when a Go program starts up that has multiple conflicting protobuf names linked into it. While it is preferable that the source of the conflict be fixed, the fatal error can be immediately worked around in one of two ways:

At compile time. The default behavior for handling conflicts can be specified at compile time with a linker-initialized variable: go build -ldflags "-X google.golang.org/protobuf/reflect/protoregistry.conflictPolicy=warn"

At program execution. The behavior for handling conflicts when executing a particular Go binary can be set with an environment variable: GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn ./main

aktau commented 1 year ago

Thanks, now I understand things better.

Thinking about your question:

My project only uses go structs generated by protobuf, and does not make rpc calls. So I would like to ask if there are any other side effects when namespace conflict is converted to warnning.

Then this conflict would lead to bugs any time a resolver is used. The cases I can think of where a Resolver is used:

It's possible there are more things that are somehow affected, but I don't think that (e.g.) standard marshalling/unmarshalling are. That should continue to work.

FGYFFFF commented 1 year ago

Thanks, now I understand things better.

Thinking about your question:

My project only uses go structs generated by protobuf, and does not make rpc calls. So I would like to ask if there are any other side effects when namespace conflict is converted to warnning.

Then this conflict would lead to bugs any time a resolver is used. The cases I can think of where a Resolver is used:

  • google.protobuf.Any.
  • Other reflection use cases: fieldpath, messagediff, anything that uses protoregistry.MessageTypeResolver.FindMessageByName.

It's possible there are more things that are somehow affected, but I don't think that (e.g.) standard marshalling/unmarshalling are. That should continue to work.

Thanks, I get it.