bradleyjkemp/grpc-tools

Cannot load proto files

Opened this issue · 5 comments

I am having trouble using --proto_descriptors and --proto_roots

I have created a proto descriptor sample using protoc --descriptor_set_out=desc.pb schema.proto

When I run ./grpc-dump -proto_descriptors "desc.pb" the output is

$ ./grpc-dump -proto_descriptors "desc.pb" 
no such file: ""

In dump.go I noticed that both clauses are using protoRoots - this appears wrong

	if protoRoots != "" {
		r, err := proto_decoder.NewFileResolver(strings.Split(protoRoots, ",")...)
		if err != nil {
			return err
		}
		resolvers = append(resolvers, r)
	}
	if protoDescriptors != "" {
		r, err := proto_decoder.NewDescriptorResolver(strings.Split(protoRoots, ",")...)
		if err != nil {
			return err
		}
		resolvers = append(resolvers, r)
	}

Changing the second one to split on protoDescriptors did not change the issue but the error changed to

$ ./grpc-dump -proto_descriptors "desc.pb" 
no such file: "desc.pb"

Can you please provide an example command line showing how to reference the proto descriptors

Thanks

Some success after I moved over to --proto-roots

After I disabled InferImportPaths in internal/proto_descriptor/protos.go LoadProtoDirectories() I am able to load most of my proto files and decode the messages as they dump.

I think my one remaining issue is with one my proto file definitions.

It is still not obvious to me the expected usage patterns of the --proto-* config parameters.

Hi @craigh1015, thank you for bearing with these bugs!

You're right, the --proto_descriptors flag is definitely broken, I'll dig into what's going on there.

What issues did you have with --proto_roots before you disabled InferImportPaths?

With the flag enabled I get:

$ go run main.go -port 64517 -proto_roots /Users/xxx/dev/yyy
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x1555040]

goroutine 1 [running]:
github.com/jhump/protoreflect/desc/protoparse.Parser.ParseFilesButDoNotLink(0xc0001c90a0, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0xc0000196a8, 0x1, ...)
	/Users/charris/go/pkg/mod/github.com/jhump/protoreflect@v1.6.0/desc/protoparse/parser.go:283 +0x210
github.com/bradleyjkemp/grpc-tools/internal/proto_descriptor.LoadProtoDirectories.func1(0xc00003a100, 0x3f, 0x1818e80, 0xc00033a000, 0x0, 0x0, 0xb, 0xc00013f7f0)
	/Users/charris/dev/grpc-tools/internal/proto_descriptor/protos.go:47 +0x1fd
path/filepath.walk(0xc00003a100, 0x3f, 0x1818e80, 0xc00033a000, 0xc00013fd88, 0x0, 0x0)

If I run in the debugger I get a Failed to continue - bad access error at go/pkg/mod/github.com/jhump/protoreflect@v1.6.0/desc/protoparse/parser.go:283

	for i, name := range filenames {
		pr := protos[name]
----->		fd := pr.fd
		if p.InterpretOptionsInUnlinkedFiles {
			pr.lenient = true
			_ = interpretFileOptions(pr, poorFileDescriptorish{FileDescriptorProto: fd})
		}
		if p.IncludeSourceCodeInfo {
			fd.SourceCodeInfo = pr.generateSourceCodeInfo()
		}
		fds[i] = fd
	}

It appears that the keys in protos are relative to my proto_root
e.g. "common/v1/protos/types.proto"
However, the value of name used to access the map is a fully qualified file name
e.g. "/Users/xxx/dev/yyy/zzz/common/v1/protos/types.proto"

I'm also running into this segmentation fault and, not being a Go developer, don't know what to do about it. If I try to provide a descriptor instead, then I get 'no such file: ""':

grpc-dump -cert mitm_certs/foobar_stage99.pem -interface 192.168.1.1 -port 4435 -log_level debug -key mitm_certs/foobar_stage99.key -proto_descriptors desc.pb
no such file: ""
Usage of grpc-dump (0.2.5):
...

we're running into this as well - absent these flags, how is grpc-dump usable @bradleyjkemp ?