Skip to content
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

reflection: use protobuf/reflect instead of go reflection, fix dynamic messages #5180

Merged
merged 7 commits into from
Feb 15, 2022

Conversation

codebutler
Copy link
Contributor

@codebutler codebutler commented Jan 30, 2022

The reflection service panics when it encounters a dynamically-created message:
https://gist.github.com/codebutler/92539e14f46bc460a6cd695b801e946a

The panic happens here:

  m, ok := reflect.Zero(reflect.PtrTo(st)).Interface().(protoMessage)

This is because st is a dynamicpb.Message which can't be created using go reflection.

Rather than add special handling for dynamic messages, migrating the reflection service to use protobuf/reflection instead of go reflection both solves the problem and cleans up a lot of code.

RELEASE NOTES:

  • [dependency] update proto lib versions & [bug] update reflection to support dynamic messages

The reflection service panics when it encounters a dynamically-created message.

The panic happens here:

  m, ok := reflect.Zero(reflect.PtrTo(st)).Interface().(protoMessage)

This is because `st` is a `dynamicpb.Message` which can't be created using go reflection.

Rather than add special handling for dynamic messages, migrating the reflection service to use protobuf/reflection instead of go reflection both solves the problem and cleans up a lot of code.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 30, 2022

CLA Signed

The committers are authorized under a signed CLA.

@menghanl menghanl added this to the 1.45 Release milestone Jan 31, 2022
Copy link
Contributor

@menghanl menghanl left a comment

Choose a reason for hiding this comment

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

Thanks for the PR.

reflection/grpc_testing/dynamic.proto Outdated Show resolved Hide resolved
@@ -78,65 +84,43 @@ func loadFileDesc(filename string) (*dpb.FileDescriptorProto, []byte) {
return fd, b
}

func loadFileDescDynamic(filename string) (*dpb.FileDescriptorProto, []byte) {
p := &protoparse.Parser{}
fds, err := p.ParseFiles(filename)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will need to call testdata.Path(filename) to avoid potential problems caused by file path.

reflection/serverreflection_test.go Outdated Show resolved Hide resolved
reflection/serverreflection.go Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Feb 6, 2022

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

@github-actions github-actions bot added the stale label Feb 6, 2022
@easwars
Copy link
Contributor

easwars commented Feb 9, 2022

@codebutler : Do you have any update here? Thanks.

@codebutler
Copy link
Contributor Author

Thanks for the review. I'll make those changes shortly, sorry for the delay.

@github-actions github-actions bot removed the stale label Feb 9, 2022
reflection/testdata/testdata.go Outdated Show resolved Hide resolved
reflection/testdata/dynamic.pb.go Outdated Show resolved Hide resolved
reflection/serverreflection.go Outdated Show resolved Hide resolved
reflection/serverreflection_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@menghanl menghanl left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes!
Overall LGTM. Some questions on the error handling.

reflection/serverreflection.go Outdated Show resolved Hide resolved
reflection/serverreflection.go Outdated Show resolved Hide resolved
reflection/serverreflection_test.go Outdated Show resolved Hide resolved
@dfawley dfawley merged commit ebc30b8 into grpc:master Feb 15, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2022
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.

4 participants