Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: proto: file "log.proto" is already registered #278

Open
cupen opened this issue May 29, 2024 · 0 comments
Open

panic: proto: file "log.proto" is already registered #278

cupen opened this issue May 29, 2024 · 0 comments

Comments

@cupen
Copy link

cupen commented May 29, 2024

我有个公共代码库需要同时支持腾讯云 CLS 跟阿里云 SLS ,但很不巧,同时使用这俩 SDK 会遇到 proto runtime panic, 查了下发现两个 SDK 包含 proto.RegisterFile("log.proto", ....)

阿里云的代码

aliyun-log-go-sdk/log.pb.go

Lines 441 to 451 in 52078e0

func init() {
proto.RegisterType((*LogContent)(nil), "sls.LogContent")
proto.RegisterType((*Log)(nil), "sls.Log")
proto.RegisterType((*LogTag)(nil), "sls.LogTag")
proto.RegisterType((*LogGroup)(nil), "sls.LogGroup")
proto.RegisterType((*SlsLogPackage)(nil), "sls.SlsLogPackage")
proto.RegisterType((*SlsLogPackageList)(nil), "sls.SlsLogPackageList")
proto.RegisterType((*LogGroupList)(nil), "sls.LogGroupList")
}
func init() { proto.RegisterFile("log.proto", fileDescriptor_a153da538f858886) }

腾讯云的代码
https://github.com/TencentCloud/tencentcloud-cls-sdk-go/blob/ad65ec0eecbd3b5e12729373ae440b760d6856d6/cls.pb.go#L334-L342

> go test ./...
ok  	github.com/gamedev-embers/zap-setup	(cached)
ok  	github.com/gamedev-embers/zap-setup/sink/aliyunsls	(cached)
panic: proto: file "log.proto" is already registered
See https://developers.google.com/protocol-buffers/docs/reference/go/faq#namespace-conflict


goroutine 1 [running]:
google.golang.org/protobuf/reflect/protoregistry.init.func1({0xe4e550?, 0x9e2fa0?}, {0xabfca0, 0xc00003ac50})
	/home/cupen/go/pkg/mod/google.golang.org/protobuf@v1.27.1/reflect/protoregistry/registry.go:54 +0x1ec
google.golang.org/protobuf/reflect/protoregistry.(*Files).RegisterFile(0xc0000121b0, {0xac9a30, 0xc0000d2c40})
	/home/cupen/go/pkg/mod/google.golang.org/protobuf@v1.27.1/reflect/protoregistry/registry.go:128 +0xbc3
google.golang.org/protobuf/internal/filedesc.Builder.Build({{0x0, 0x0}, {0xc0001c4a80, 0x2a7, 0x380}, 0x0, 0x7, 0x0, 0x0, {0xac16d8, ...}, ...})
	/home/cupen/go/pkg/mod/google.golang.org/protobuf@v1.27.1/internal/filedesc/build.go:113 +0x1d6
github.com/golang/protobuf/proto.RegisterFile({0x9f3957, 0x9}, {0xe1b5c0, 0x19c, 0x19c})
	/home/cupen/go/pkg/mod/github.com/golang/protobuf@v1.5.0/proto/registry.go:48 +0x148
github.com/aliyun/aliyun-log-go-sdk.init.1()
	/home/cupen/go/pkg/mod/github.com/aliyun/aliyun-log-go-sdk@v0.1.75/log.pb.go:451 +0x34
FAIL	github.com/gamedev-embers/zap-setup/sink/tencentcls	0.006s
FAIL

重现步骤:

git clone https://github.com/gamedev-embers/zap-setup
cd zap-setup
go test ./...

我尝试去腾讯云 CLS SDK 那边提个 issue. 等反馈。
TencentCloud/tencentcloud-cls-sdk-go#11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant