From 99b558fa7c189c95ecc85441d57bfb998f1479be Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Fri, 10 Dec 2021 22:25:24 +0100 Subject: [PATCH] fix: Handle duplicate registration of protocol-buffer files gracefully. (#10188) --- plugins/parsers/xpath/protocolbuffer_document.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/parsers/xpath/protocolbuffer_document.go b/plugins/parsers/xpath/protocolbuffer_document.go index 4ae88812d96bb..55e96e46308fe 100644 --- a/plugins/parsers/xpath/protocolbuffer_document.go +++ b/plugins/parsers/xpath/protocolbuffer_document.go @@ -1,6 +1,7 @@ package xpath import ( + "errors" "fmt" "sort" "strings" @@ -55,6 +56,13 @@ func (d *protobufDocument) Init() error { if err != nil { return fmt.Errorf("creating file descriptor from proto failed: %v", err) } + if _, err := protoregistry.GlobalFiles.FindFileByPath(fileDesc.Path()); !errors.Is(err, protoregistry.NotFound) { + if err != nil { + return fmt.Errorf("searching for file %q in registry failed: %v", fileDesc.Path(), err) + } + d.Log.Warnf("Protocol buffer with path %q already registered. Skipping...", fileDesc.Path()) + continue + } if err := protoregistry.GlobalFiles.RegisterFile(fileDesc); err != nil { return fmt.Errorf("registering file descriptor %q failed: %v", fileDesc.Package(), err) }