-
Notifications
You must be signed in to change notification settings - Fork 806
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
grpc-gateway calls golang/protobuf/jsonpb #178
Comments
This is a bit of sed that helps:
|
Damn that sucks :( I do have an extension that imports golang/protobuf instead of gogo/protobuf, maybe that can help? |
I'm not sure this is a "real" issue - truth is that using The workaround isn't so bad, see my solution in cockroachdb/cockroach@2101119 |
Ok maybe it just bothers me :-)
|
Tamir, agreed. However if your vendored dependency used I think that having golang/protobuf generate MarshalJSON functions that use On Mon, 16 May 2016, 20:53 Walter Schulze, [email protected] wrote:
|
Sorry I replied to wrong issue
|
Line 58 of jsonpb_marshaler should probably be jsonpb.Unmarshal not
|
I also think the generated MarshalJSON functions will solve all a lot of problems. |
Maybe we should make an issue with grpc-gateway to allow us to inject our own jsonpb marshaler codec, just like grpc-go allows you to inject a codec interface? |
gRPC gateway already allows one to do that. It's just confusing as hell. I actually think that double registration would be the better solution here. |
How is it confusing, maybe you can explain more? Worst case for someone else finding this issue. I haven't used grpc-gateway. I have only read about it. |
For example: you use the default grpc gateway codes and gogo as your proto On Mon, 12 Sep 2016, 17:58 Walter Schulze, [email protected] wrote:
|
Ok so everything works in that case? |
Wow that is a lot of quite complex code, but as you said there are other issues with using golang/protobuf/jsonpb with gogoprotobuf generated structures, like non-nullable non-scalar fields. Have you brought this up with grpc-gateway? I would think that there would be an easier interface to implement. |
I haven't, but it's probably worthwhile to do so. Having to copy |
Whoever opens this issue could CC me in on the issue. I would like to at least follow. |
Doesn't seem like the issue was ever opened #212 (comment) |
We're currently getting a |
I would report this issue if I was using grpc-gateway, but unfortunately I am not. Also I don't perfectly understand. I am guessing. I would suggest putting in a panic at the place this warning it being printed out to find out how this call is happening. And then report this issue. |
Sounds reasonable, I'll give it a go |
For reference, I've managed to get a panic traceback, just posting it here before raising it against grpc-gateway: 2016/11/01 11:22:15 http2: panic serving 127.0.0.1:49722: proto: no coders for int
goroutine 427 [running]:
net/http.(*http2serverConn).runHandler.func1(0xc4201381c0, 0xc4201e7f5f, 0xc420378b40)
/usr/local/go/src/net/http/h2_bundle.go:4304 +0xd1
panic(0x8ac880, 0xc4202a6770)
/usr/local/go/src/runtime/panic.go:458 +0x243
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/proto.(*Properties).setEncAndDec(0xc42008ef20, 0xbfd8e0, 0x8ac140, 0xc4201e6eb0, 0x1)
~/myrepo/vendor/github.com/gogo/protobuf/proto/properties.go:381 +0x382
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/proto.(*Properties).init(0xc42008ef20, 0xbfd8e0, 0x8ac140, 0x88a710, 0x4, 0x88a720, 0x11, 0xc4201e6eb0, 0xc42008ef01)
~/myrepo/vendor/github.com/gogo/protobuf/proto/properties.go:713 +0xcb
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/proto.(*Properties).Init(0xc42008ef20, 0xbfd8e0, 0x8ac140, 0x88a710, 0x4, 0x88a720, 0x11, 0xc4201e6eb0)
~/myrepo/vendor/github.com/gogo/protobuf/proto/properties.go:699 +0x7f
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/jsonpb.jsonProperties(0x88a710, 0x4, 0x0, 0x0, 0xbfd8e0, 0x8ac140, 0x88a716, 0x28, 0x10, 0xc4202a65a8, ...)
~/myrepo/vendor/github.com/gogo/protobuf/jsonpb/jsonpb.go:892 +0xe1
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/jsonpb.(*Marshaler).marshalObject(0xc4202ccf80, 0xc4201e7518, 0x7f9012377670, 0xc4202ae2e0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc4202ec000)
~/myrepo/vendor/github.com/gogo/protobuf/jsonpb/jsonpb.go:222 +0x406
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/jsonpb.(*Marshaler).Marshal(0xc4202ccf80, 0xbeecc0, 0xc420308380, 0x7f9012377670, 0xc4202ae2e0, 0x1, 0xc420308380)
~/myrepo/vendor/github.com/gogo/protobuf/jsonpb/jsonpb.go:79 +0xca
github.com/johanbrandhorst/myrepo/vendor/github.com/gogo/protobuf/jsonpb.(*Marshaler).Marshal-fm(0xbeecc0, 0xc420308380, 0x7f9012377670, 0xc4202ae2e0, 0x8f9501, 0xc4202a62c0)
~/myrepo/vendor/github.com/cockroachdb/cockroach/pkg/util/httputil/http.go:71 +0x52
github.com/johanbrandhorst/myrepo/vendor/github.com/cockroachdb/cockroach/pkg/util/protoutil.(*JSONPb).marshal(0xc4202ccf80, 0x8e4580, 0xc4202ae2e0, 0x411a68, 0x20, 0x8f9540, 0x96a701, 0xc4202ae2e0)
~/myrepo/vendor/github.com/cockroachdb/cockroach/pkg/util/protoutil/jsonpb_marshal.go:57 +0x118
github.com/johanbrandhorst/myrepo/vendor/github.com/cockroachdb/cockroach/pkg/util/protoutil.(*JSONPb).Marshal(0xc4202ccf80, 0x8e4580, 0xc4202ae2e0, 0x35, 0x10, 0x8ed040, 0xbf75c0, 0xc4202ac720)
~/myrepo/vendor/github.com/cockroachdb/cockroach/pkg/util/protoutil/jsonpb_marshal.go:48 +0x3f
github.com/johanbrandhorst/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime.DefaultHTTPError(0x7f90123337c0, 0xc4202ac720, 0xbf89a0, 0xc4202ccf80, 0xbf6b00, 0xc4201381c0, 0xc42037e960, 0xbef700, 0xc4202ae2c0)
~/myrepo/vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/errors.go:91 +0x1cf
net/http.(*ServeMux).ServeHTTP(0xc420243680, 0xbf6b00, 0xc4201381c0, 0xc42037e960)
/usr/local/go/src/net/http/server.go:2022 +0x7f
....
<my code>
....
created by net/http.(*http2serverConn).processHeaders
/usr/local/go/src/net/http/h2_bundle.go:4092 +0x6e2 |
Wow ok that trace is very interesting. |
With panic(fmt.Sprintf("proto: no coders for Kind: %v, StructField: %v", t1, f))
|
Where is it finding this |
Using the debugger, I get this value for the valueField
<reflect.StructField>
Name:"Code"
PkgPath:""
Type:<reflect.Type>
Tag:"protobuf:"bytes,2,name=code" json:"code""
Offset:16
Index:<[]int> (length: 1, cap: 1)
Anonymous:false The value of |
Ok I'm stumped. Where is this Code field coming from? |
@tamird even without the use of |
I was able to reproduce the |
Good work |
I guess since grpc-ecosystem/grpc-gateway#259 is closed this issue can also be closed? |
At least the |
@tamird This link is broken |
Updated the link. |
The underlying issue here has reared it's head again in enum parsing in the grpc-gateway. See grpc-ecosystem/grpc-gateway#320. Again it is because gogo/protobuf RegisterEnum doesn't register against golang/protobuf and so when grpc-gateway attempts to map an enum it fails to find it. |
Should we create a plugin to allow you to register with both gogoprotobuf and golang/protobuf or something like that. |
I would like something like that for better cross-compatibility. |
It would be useful for me (to try and to only build one new feature) if you could provide a repo which produces this problem, with an easy way for me to test. |
@awalterschulze Pinging you on the gopher slack for further discussion |
Can we please keep the discussion here.
…On Thu, 2 Mar 2017 at 15:28 Johan Brandhorst ***@***.***> wrote:
@awalterschulze <https://github.com/awalterschulze> Pinging you on the
gopher slack for further discussion
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#178 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvsLdvRKc-C8MqJsV24Ks2eCsyBT8FQks5rhtHvgaJpZM4Id0EI>
.
|
Okay, my org would have no problems with a plugin that doesn't support ptypes.Any or proto2 extensions. What kind of example are you interested in? The reason it's not working right now with the grpc-gateway is because it looks in a map created by |
Why does it look at this map? Is it only for json marshaling?
…On Thu, 2 Mar 2017, 15:36 Johan Brandhorst, ***@***.***> wrote:
Okay, my org would have no problems with a plugin that doesn't support
ptypes.Any or proto2 extensions. What kind of example are you interested
in? The reason it's not working right now with the grpc-gateway is because
it looks in a map created by golang/proto.RegisterEnum while all our
generated files call gogo/proto.RegisterEnum
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#178 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvsLS7onl0IEvvXczOzTMTYk1XiE1c9ks5rhtQDgaJpZM4Id0EI>
.
|
@awalterschulze It looks at the map so that it can map from the enum string to the enum code and vice versa. It's to allow things like |
This is the relevant code: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/runtime/query.go#L150 |
As a side note, if this is at all unpleasant to consider, @mwitkow sed commands can be run post-generation to fix this issue, so it doesn't need to implemented at this level. |
Ah ok, so grpc-gateway uses this in a totally different way. Thats unfortunate. |
Indeed |
Ok so you need a plugin that registers messages, enums, etc with both golang/protobuf and gogo/protobuf. |
I'll get on it 😄 |
This particular bug bit us:
To properly serialize/deserailize enums in
jsonpb
you need to call RegisterEnum.gogo/protobuf
-generated messages register withgogo/protobuf/properties.go
. However, if you have a library that is not under your control (e.g. gRPC Gateway), it will be using standardgolang/jsonpb
and thus thegolang/protobuf/properties
registration. Thus, any library usinggolang/jsonpb
will not know about enums field maps.Can we have a fix for this? Proposals include:
gogo
register by only withgolang/protobuf
gogo
register with both, or passing it up.The text was updated successfully, but these errors were encountered: