You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If grpc-dump is run with -proto_roots, it fails with:
WARN[0020] Failed to search for unknown fields in message =proto_decoder error="failed to enrich decode descriptor: failed to search nested field init: failed to search nested field snapshot: internal: got nil message"
WARN[0020] Failed to search for unknown fields in message =proto_decoder error="failed to enrich decode descriptor: failed to search nested field init: internal: got nil message"
WARN[0020] Failed to search for unknown fields in message =proto_decoder error="failed to enrich decode descriptor: failed to search nested field init: failed to search nested field snapshot: internal: got nil message"
WARN[0020] Failed to search for unknown fields in message =proto_decoder error="failed to enrich decode descriptor: failed to search nested field reply: failed to search nested field client_action: failed to search nested field forward: internal: got nil message"
If grpc-dump is run without -proto_roots it does not fail but message fields are just named with their corresponding tags:
Analysis a) The error got nil message is coming from proto_decoder.unknownFieldResolver#enrichMessageand seems to be triggered by a recursive call to itself whenever the condition dynamicNestedMessage == nilis met here. I read the comment here about message being nil and a potential race condition, but it never occurred to me during my debugging sessions for this issue.
Returning nil in enrichMessage in this case seems to solve this issue. I'm not sure if this is valid, but I did not miss anything during my sessions doing so.
b) As soon as this is fixed, I got an error like this
FATA[0013] Failed to marshal rpc error="json: error calling MarshalJSON for type *dynamic.Message: unknown message type "com.example.shoppingcart.GetShoppingCart"
which is coming from dynamic.AnyResolver#Resolve of protoreflect and is triggered by dump#dumpInterceptor which tries to json.Marshal the RPC struct with its collected messages. json.Marshal in its path down to marshal types, will call ultimatively dynamic.Messages#MarshalJSON and will fail as the jsonpb.Marshaler config lacks any AnyResolver that, when json.Marshal calls it, could resolve a messages type not well known or proto.MessageType would find and then ultimatively fails with
unknown message type
Fix
Getting messages resolved using proto.MessageTypeand get then registered by proto.RegisterType is probably a bad idea and should only used by generated Go types by protoc.
After some debugging and tests I got with a solution where dumpInterceptor wraps a messages event into a type that implements json.Marshal interface and configures an AnyResolver for the jsonpb.Marshaler knowing all FileDescriptors the proto_descriptor.LoadProtoDirectories function ever sees during the load of the protofiles provided by the -proto_roots argument.
This is implemented in this PR #97 and works for the use case mentioned at the beginning of this issue.
The text was updated successfully, but these errors were encountered:
marcellanz
added a commit
to mrcllnz/grpc-tools
that referenced
this issue
May 1, 2020
This might be a duplicate of #88 but I think I have a fix for that and it may fail differently for me.
Given
https://github.com/cloudstateio/go-support/tree/master/protobuf
If grpc-dump is run with
-proto_roots
, it fails with:If grpc-dump is run without
-proto_roots
it does not fail but message fields are just named with their corresponding tags:This message should look like this if encoded properly:
Analysis
a) The error
got nil message
is coming fromproto_decoder.unknownFieldResolver#enrichMessage
and seems to be triggered by a recursive call to itself whenever the conditiondynamicNestedMessage == nil
is met here. I read the comment here about message being nil and a potential race condition, but it never occurred to me during my debugging sessions for this issue.Returning nil in
enrichMessage
in this case seems to solve this issue. I'm not sure if this is valid, but I did not miss anything during my sessions doing so.b) As soon as this is fixed, I got an error like this
which is coming from
dynamic.AnyResolver#Resolve
of protoreflect and is triggered by dump#dumpInterceptor which tries tojson.Marshal
the RPC struct with its collected messages.json.Marshal
in its path down to marshal types, will call ultimativelydynamic.Messages#MarshalJSON
and will fail as thejsonpb.Marshaler
config lacks anyAnyResolver
that, whenjson.Marshal
calls it, could resolve a messages type not well known orproto.MessageType
would find and then ultimatively fails withFix
Getting messages resolved using
proto.MessageType
and get then registered byproto.RegisterType
is probably a bad idea and should only used by generated Go types by protoc.After some debugging and tests I got with a solution where
dumpInterceptor
wraps a messages event into a type that implementsjson.Marshal
interface and configures an AnyResolver for thejsonpb.Marshaler
knowing all FileDescriptors theproto_descriptor.LoadProtoDirectories
function ever sees during the load of the protofiles provided by the-proto_roots
argument.This is implemented in this PR #97 and works for the use case mentioned at the beginning of this issue.
The text was updated successfully, but these errors were encountered: