-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Server nil returns cause problems #532
Comments
I have no idea what func you are talking about. Can you elaborate? |
Apologies, that was very vague of me. Here's more details. ProtoBuf
Server
Any client is fine. |
@ashishgandhi It works fine I believe. You need to return the error correctly, not nil response + nil error. |
what prevents you from doing: func (_server) Do(context.Context, *test.Empty) (_test.Empty, error) { |
Well, nothing prevents me from doing that. But it'd be nice to not crash the server because of this? Same reason why the standard library |
I would think crash is right thing to do because this is a fatal error due to the local operations. |
I've just wasted a few hours on this, because in my case crash was happening without any diagnostic info or anything (just exit 1, I suppose). |
I got this error:
Refer to https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L265, the nil message case has been considered. So the |
@songshine Can you give an example for this? Or a reproduction of the error? |
@menghanl please think about the example from @ashishgandhi
so when the code run into the line https://github.com/grpc/grpc-go/blob/master/rpc_util.go#L265,
the |
I think the fix should be
So that the behavior will be, if the error returned by service handler is In the case of using protobuf and |
In Go it is pretty idiomatic to return
nil, err
from a func when we encounter an error when the return values are a pointer and an error. The servers fail to marshal thisnil
while sending back a response to the client; and fatal logs. I think it might be better to donew(T)
for the user before marshaling.The text was updated successfully, but these errors were encountered: