grpc / grpc-go

The Go language implementation of gRPC. HTTP/2 based RPC
https://grpc.io
Apache License 2.0
21.03k stars 4.37k forks source link

Cannot use 'ms' (type *messageState) as the type protoreflect.Message Type does not implement 'protoreflect.Message' #4980

Closed dodoao closed 2 years ago

dodoao commented 2 years ago

NOTE: if you are reporting is a potential security vulnerability or a crash, please follow our CVE process at https://github.com/grpc/proposal/blob/master/P4-grpc-cve-process.md instead of filing an issue here.

Please see the FAQ in our main README.md, then answer the questions below before submitting your issue.

What version of gRPC are you using?

libprotoc 3.19.1

What version of Go are you using (go version)?

go version go1.17.3

What operating system (Linux, Windows, …) and version?

windows 10 /amd64

What did you do?

go to github.com/grpc/grpc-go/blob/master/examples/route_guide/routeguide/route_guide.pb.go. Line 70

run this code protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative route_guide.proto Same result

ICSZ`FFIB5OGL OYHK MC6

E)U%2{D4Q%D3(`S3V6U0C93

What did you expect to see?

What did you see instead?

elricli commented 2 years ago

Same

easwars commented 2 years ago

Did you follow the instructions in https://grpc.io/docs/languages/go/quickstart/ to install protoc-gen-go-grpc?

easwars commented 2 years ago

It would also be worth checking your protoc-gen-go version. According to the quickstart, it should be $ go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26

elricli commented 2 years ago

Did you follow the instructions in https://grpc.io/docs/languages/go/quickstart/ to install protoc-gen-go-grpc?

Same. But what confuses me is that the code still runs normally.

version:

❯ protoc-gen-go-grpc --version
protoc-gen-go-grpc 1.1.0

❯ protoc-gen-go --version
protoc-gen-go.exe v1.26.0

image image

dodoao commented 2 years ago

Did you follow the instructions in https://grpc.io/docs/languages/go/quickstart/ to install protoc-gen-go-grpc?

I did . I think you can look here: github.com/grpc/grpc-go/blob/master/examples/route_guide/routeguide/route_guide.pb.go. Line 70

github-actions[bot] commented 2 years ago

This issue 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.

dfawley commented 2 years ago

This is an issue with your protoc-gen-go version, not protoc-gen-go-grpc, since it's the messages and not the services that are affected. Make sure you are using the latest generator from google.golang.org/protobuf (https://github.com/protocolbuffers/protobuf-go) and make sure protoc is running that version (it looks in your path IIRC) by looking at the output file and ensuring the proper version is shown at the top in the comments.

maxihafer commented 2 years ago

I am currently experiencing the same issue, it only happens when generating under Apple Silicone (darwin/arm64). I use a docker image with the following versions:

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
//  protoc-gen-go v1.27.1
//  protoc        v3.19.1
dfawley commented 2 years ago

I'm going to close this, as it's likely either:

  1. A problem with the protobuf library version you are using (not from the proper repo / not new enough? check your go.mod)
  2. A problem with the protoc-gen-go version you are using

Either way, this repo owns the code generator for the grpc stubs only, and the above errors are related to the base protobuf message generation/usage. If you're still having trouble, please try stack overflow or the protobuf repo (https://github.com/protocolbuffers/protobuf-go) for help.

If you are following some instructions we publish (e.g. https://grpc.io/docs/languages/go/quickstart/) and find there is an error there, please let us know.

leozmm commented 2 years ago

Hi, thanks for your time, but I recently occured with the same problem in my GoLand IDE.

The GoLand said exactly the same as @dodoao commented above:

Cannot use 'ms' (type messageState) as the type protoreflect.Message Type does not implement 'protoreflect.Message' __need the method: ProtoMethods() methods have the method: ProtoMethods() *protoiface.Methods__ image

The same notice also shows up in file "google.golang.org/protobuf@v1.27.1/internal/impl/message_reflect.go": image

I had my go of version:1.17.3 and protoc-gen-go of version:v1.27.1

I tracked method ProtoMethods which messageState implemented, and finally found that the method return value is pointer of type protoiface.Methods, while the interfae protoreflect.Message requires the return value of method ProtoMethods be pointer of type protoreflect.methods.

I found comments of protoreflect.Message.ProtoMethods said:

The returned methods type is identical to "google.golang.org/protobuf/runtime/protoiface".Methods. image

but I couldnt figure out how it comes type protoiface.Methods is identical to type protoreflect.methods, although these two have the same fields. Maybe it's the reason why my IDE couldnt recognize type messageState as implementation of interface protoreflect.Message ?

dfawley commented 2 years ago

As I said in the comment directly above, this is not the right repo for this issue. This is a message, generated by protoc-gen-go, not protoc-gen-go-grpc.

If you are following some instructions we publish (e.g. https://grpc.io/docs/languages/go/quickstart/) and find there is an error there, please let us know.

leozmm commented 2 years ago

As I said in the comment directly above, this is not the right repo for this issue. This is a message, generated by protoc-gen-go, not protoc-gen-go-grpc.

If you are following some instructions we publish (e.g. https://grpc.io/docs/languages/go/quickstart/) and find there is an error there, please let us know.

ok, that's my fault, but thanks. have a nice day btw

choyri commented 2 years ago

I think it's GoLand's problem. I got this message today after upgrading to 2021.3, but it was fine after downgrading to 2021.2.4.

My Environment:

macOS 12.0.1
go 1.17.3
libprotoc 3.17.3 / 3.19.1
protoc-gen-go v1.27.1

See: https://youtrack.jetbrains.com/issue/GO-12060

jony4 commented 2 years ago

me too

dipjyotimetia commented 2 years ago

same here 👍

code4happylife commented 2 years ago

same here

pakuwa commented 2 years ago

same here

menghanl commented 2 years ago

I'm locking this thread since the problem is resolved. Please file a new issue if there are other questions. Thanks!