etcd icon indicating copy to clipboard operation
etcd copied to clipboard

option go_package in proto files

Open semyon-dev opened this issue 1 year ago • 10 comments

What would you like to be added?

There has been a commit in the main branch for at least 10 months that adds option go_package: https://github.com/etcd-io/etcd/blob/main/server/storage/wal/walpb/record.proto#L7

But the latest version (v3.5.14) does not have this option, please add this option (or commit) to the next version.

Why is this needed?

I am using two dependencies (one of them is etcd) that have the same proto files - record.proto, and because of this there is a conflict. To resolve this conflict, option go_package is needed.

Now I have to do this: os.Setenv("GOLANG_PROTOBUF_REGISTRATION_CONFLICT", "ignore") or I will get a panic:

panic: proto: file "record.proto" is already registered
See https://protobuf.dev/reference/go/faq#namespace-conflict


goroutine 1 [running]:
google.golang.org/protobuf/reflect/protoregistry.init.func1({0x7ff6c0cc8e90?, 0x7ff6c111ba40?}, {0x7ff6c1716f60, 0xc00031d2b0})
	C:/Users/user/go/src/github.com/pkg/mod/google.golang.org/[email protected]/reflect/protoregistry/registry.go:56 +0x1ec
google.golang.org/protobuf/reflect/protoregistry.(*Files).RegisterFile(0xc000008ed0, {0x7ff6c1746458, 0xc000331880})
	C:/Users/user/go/src/github.com/pkg/mod/google.golang.org/[email protected]/reflect/protoregistry/registry.go:130 +0xbc3
google.golang.org/protobuf/internal/filedesc.Builder.Build({{0x0, 0x0}, {0xc00032f600, 0x11d, 0x200}, 0x0, 0x2, 0x0, 0x0, {0x7ff6c171e9b0, ...}, ...})
	C:/Users/user/go/src/github.com/pkg/mod/google.golang.org/[email protected]/internal/filedesc/build.go:112 +0x1d6
github.com/golang/protobuf/proto.RegisterFile({0x7ff6c115751a, 0xc}, {0x7ff6c0c48940, 0xea, 0xea})
	C:/Users/user/go/src/github.com/pkg/mod/github.com/golang/[email protected]/proto/registry.go:48 +0x148
go.etcd.io/etcd/server/v3/wal/walpb.init.1()
	C:/Users/user/go/src/github.com/pkg/mod/go.etcd.io/etcd/server/[email protected]/wal/walpb/record.pb.go:119 +0x34

Process finished with the exit code 2

semyon-dev avatar Jul 17 '24 14:07 semyon-dev

But the latest version (v3.5.14) does not have this option, please add this option (or commit) to the next version.

Have you confirmed that it's working if you depend on etcd main branch?

ahrtr avatar Jul 19 '24 12:07 ahrtr

But the latest version (v3.5.14) does not have this option, please add this option (or commit) to the next version.

Have you confirmed that it's working if you depend on etcd main branch?

I'm sorry, the problem remained on the main branch, but I don't understand why

semyon-dev avatar Jul 22 '24 13:07 semyon-dev

the problem remained on the main branch, but I don't understand why

Thanks for the feedback. It means that it won't hep to backport the option go_package change to 3.5.

I suggest you to raise this issue/question in protobuf community. https://github.com/protocolbuffers/protobuf-go

ahrtr avatar Jul 22 '24 14:07 ahrtr

Based on https://protobuf.dev/reference/go/faq/#namespace-conflict, it's a best practice to specify a package name in .proto file. So let's keep this ticket open until the root cause is clear.

ahrtr avatar Jul 22 '24 14:07 ahrtr

This issue is caused by the line: https://github.com/etcd-io/etcd/blob/c983744ac20103fe1339766cbaa5f5a5c41d5581/server/storage/wal/walpb/record.pb.go#L119

Newer versions of protoc don't generate such calls. This is not related to the package directive in the .proto file. It seems like deleting and re-generating the auto-generated go file resolves the issue.

aead avatar Mar 27 '25 14:03 aead

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar May 27 '25 00:05 github-actions[bot]

The conflict remains if I create and use record.proto in the project even with the go_package option, tested with the latest versions: libprotoc 31.1, etcd v3.6.1, protoc-gen-go v1.36.6, protoc-gen-go-grpc 1.5.1. A panic occurs when calling build in record.pb.go:

func file_record_proto_init() {
	if File_record_proto != nil {
		return
	}
	type x struct{}
	out := protoimpl.TypeBuilder{
		File: protoimpl.DescBuilder{
			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
			RawDescriptor: unsafe.Slice(unsafe.StringData(file_record_proto_rawDesc), len(file_record_proto_rawDesc)),
			NumEnums:      0,
			NumMessages:   0,
			NumExtensions: 0,
			NumServices:   0,
		},
		GoTypes:           file_record_proto_goTypes,
		DependencyIndexes: file_record_proto_depIdxs,
	}.Build() // PANIC HERE
	File_record_proto = out.File
	file_record_proto_goTypes = nil
	file_record_proto_depIdxs = nil
}

Logs:

panic: proto: file "record.proto" is already registered See https://protobuf.dev/reference/go/faq#namespace-conflict

goroutine 1 [running]: google.golang.org/protobuf/reflect/protoregistry.init.func1({0x7ff7f4efb350?, 0x7ff7f545dbe0?}, {0x7ff7f5971280, 0xc0004714b0}) C:/Users/user/go/pkg/mod/google.golang.org/[email protected]/reflect/protoregistry/registry.go:56 +0x1ec google.golang.org/protobuf/reflect/protoregistry.(*Files).RegisterFile(0xc000008b88, {0x7ff7f59a97f8, 0xc000706960}) C:/Users/user/go/pkg/mod/google.golang.org/[email protected]/reflect/protoregistry/registry.go:130 +0xb63 google.golang.org/protobuf/internal/filedesc.Builder.Build({{0x7ff7f4ff3e9f, 0x2a}, {0x7ff7f5526bbe, 0x4e, 0x4e}, 0x0, 0x0, 0x0, 0x0, {0x7ff7f597b240, ...}, ...}) C:/Users/user/go/pkg/mod/google.golang.org/[email protected]/internal/filedesc/build.go:112 +0x1d6 google.golang.org/protobuf/internal/filetype.Builder.Build({{{0x7ff7f4ff3e9f, 0x2a}, {0x7ff7f5526bbe, 0x4e, 0x4e}, 0x0, 0x0, 0x0, 0x0, {0x0, ...}, ...}, ...}) C:/Users/user/go/pkg/mod/google.golang.org/[email protected]/internal/filetype/build.go:138 +0x17d github.com/singnet/snet-daemon/v5/training.file_record_proto_init() C:/Users/user/go/src/github.com/singnet/snet-daemon/training/record.pb.go:55 +0x15b github.com/singnet/snet-daemon/v5/training.init.0() C:/Users/user/go/src/github.com/singnet/snet-daemon/training/record.pb.go:38 +0xf

Process finished with the exit code 2

record.proto:

syntax = "proto3";
package training;
option go_package = "github.com/singnet/snet-daemon/v5/training";

semyon-dev avatar Jun 09 '25 11:06 semyon-dev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 09 '25 00:08 github-actions[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Oct 09 '25 00:10 github-actions[bot]