Skip to content

Conversation

@menghanl
Copy link
Contributor

fixes #4213

The type mismatch can happen if

  1. user is using a non-proto generated code, so the message is not proto.Message
  2. the proto codec is picked (e.g. on receiving side, by content-type application/grpc+subtype)

@menghanl menghanl requested a review from dfawley February 19, 2021 01:08
@menghanl menghanl added this to the 1.37 Release milestone Feb 19, 2021
return proto.Marshal(v.(proto.Message))
vv, ok := v.(proto.Message)
if !ok {
return nil, fmt.Errorf("failed to marshal, message is %T, want proto", v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: proto.Message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return proto.Unmarshal(data, v.(proto.Message))
vv, ok := v.(proto.Message)
if !ok {
return fmt.Errorf("failed to marshal, message is %T, want proto", v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"unmarshal", proto.Message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dfawley dfawley changed the title encoding proto: not panic when types do not match encoding/proto: do not panic when types do not match Feb 22, 2021
@menghanl menghanl force-pushed the not_panic_proto_codec branch from 2a66eac to f161aa5 Compare February 23, 2021 00:05
@menghanl menghanl merged commit dabedfb into grpc:master Feb 23, 2021
@menghanl menghanl deleted the not_panic_proto_codec branch February 23, 2021 17:47
menghanl added a commit to menghanl/grpc-go that referenced this pull request Feb 24, 2021
@menghanl menghanl modified the milestones: 1.37 Release, 1.36 Release Feb 24, 2021
menghanl added a commit to menghanl/grpc-go that referenced this pull request Feb 26, 2021
menghanl added a commit to menghanl/grpc-go that referenced this pull request Feb 26, 2021
menghanl added a commit that referenced this pull request Mar 11, 2021
Co-authored-by: Easwar Swaminathan <[email protected]>

This is a cherry pick of 
- encoding/proto: do not panic when types do not match (#4218)
- xds: add env var protection for client-side security (#4247)
menghanl added a commit that referenced this pull request Mar 11, 2021
Co-authored-by: Easwar Swaminathan <[email protected]>

This is a cherry pick of 
- encoding/proto: do not panic when types do not match (#4218)
- xds: add env var protection for client-side security (#4247)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flatbuffers codec] Content-subtype only set for go lang

3 participants