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

server: handle context errors returned by service handler #5156

Merged
merged 4 commits into from Jan 26, 2022

Conversation

menghanl
Copy link
Contributor

@menghanl menghanl commented Jan 20, 2022

fixes #5155

RELEASE NOTES:

  • server: convert context errors returned by service handlers to status with the correct status code (Canceled or DeadlineExceeded), instead of Unknown

defer cancel()
_, err := ss.Client.EmptyCall(ctx, &testpb.Empty{})
if s, ok := status.FromError(err); !ok || s.Code() != codes.DeadlineExceeded {
t.Fatalf("ss.Client.EmptyCall(ctx, _) = _, %v; want _, <status with Code()=DeadlineExceeded>", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid underscores in these error message. They make them really hard to read and add no value. I know this is the way many existing tests report errors, but do we need to continue doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you suggesting deleting _,?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thanks :)

Copy link
Member

Choose a reason for hiding this comment

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

add no value

I have to disagree on this a bit. They show the parameter/return signature of the function being called accurately. If a function accepts 3 values and returns 3, but you only show 1 or 2 of each of them, how do you know what the values represent?

If you want to remove them here then don't imply the function only returns one value. Do something like this instead:

t.Fatalf("ss.Client.EmptyCall() got error %v; want status with Code()=DeadlineExceeded", err)

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

Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

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

Please update the docstrings here:

grpc-go/stream.go

Lines 48 to 52 in 14c1138

// StreamHandler defines the handler called by gRPC server to complete the
// execution of a streaming RPC. If a StreamHandler returns an error, it
// should be produced by the status package, or else gRPC will use
// codes.Unknown as the status code and err.Error() as the status message
// of the RPC.

and here:

grpc-go/interceptor.go

Lines 74 to 77 in 14c1138

// UnaryHandler defines the handler invoked by UnaryServerInterceptor to complete the normal
// execution of a unary RPC. If a UnaryHandler returns an error, it should be produced by the
// status package, or else gRPC will use codes.Unknown as the status code and err.Error() as
// the status message of the RPC.

@dfawley dfawley assigned menghanl and unassigned dfawley Jan 21, 2022
@menghanl
Copy link
Contributor Author

Done

…service handler

RELEASE NOTES:
* server: convert context errors returned by service handlers to status with the correct status code, instead of Unknown
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Behavior Change Behavior changes not categorized as bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server sometimes returns "rpc error: code = Unknown" instead of "code = codees.DeadlineExceeded"
3 participants