jhump / protoreflect

Reflection (Rich Descriptors) for Go Protocol Buffers
Apache License 2.0
1.33k stars 170 forks source link

grpcreflect: add flag to make Client try to be lenient in the face of missing dependencies #604

Closed jhump closed 5 months ago

jhump commented 5 months ago

Ever since v1.15 was released, the grpcreflect package inadvertently became more strict:

  1. It suddenly wraps the protobuf-go runtime's protoreflect descriptors, which means creating descriptors uses the protobuf-go runtime's protodesc package. That package is more strict and does more validation than this repo's desc package.
  2. Before v1.61.0 of the grpc-go runtime, the reflection service would send back invalid file descriptors -- "placeholder" values that represent missing dependencies. Pre-v1.15 of this repo, if the file was actually unused or only provided custom options, no problem. The desc package was doing enough validation to realize the descriptor was junk. But starting with v1.15, this would result in an error.

So, if a file was imported only for custom options (for things like OpenAPI annotations, validation options, etc), it was previously allowed to be missing. But that is no longer the case.

This has actually caused some issues for users of grpcurl and grpcui, which use the grpcreflect package in this repo. See, for example, https://github.com/fullstorydev/grpcurl/issues/423, https://github.com/fullstorydev/grpcurl/issues/432, https://github.com/fullstorydev/grpcurl/issues/451, and https://github.com/fullstorydev/grpcui/issues/279.

In these cases, prior to grpcurl pulling in v1.15 of this repo, things worked and the files that would later cause issues were effectively ignored (and okay to ignore because they were just providing custom options, not necessary for the descriptors to actually be linked). But since v1.15, they fail.

This branch adds a new method to *grpcreflect.Client, allowing callers to opt-in to lenient behavior that will effectively ignore "file not found" errors when downloading the schema from the server. If the missing file is not actually necessary to link the descriptors, the client will not complain about the missing file and instead return the requested schema (though any custom options provided by the missing files will be uninterpretable).