Error handling gRPC server side.

802 views
Skip to first unread message

John Coffey

unread,
Aug 5, 2016, 4:27:11 PM8/5/16
to grpc.io
I have a grpc c++ client & server working together.  Things work well unless the server encounters a condition (when mpFlag is false) where it cannot return a protobuf response and instead it wants to return a grpc::StatusCode::UNAVAILABLE.  The protobuf and server side code are shown below:  When the mpFlag is false (and therefore the response is not filled in) the server console indicates:

Server listening on 0.0.0.0:50051
E0805 16:19:29.345000000 37328 chttp2_transport.c:1810] close_transport: {"creat
ed":"@1470428369.345000000","description":"Failed parsing HTTP/2","file":"c:\mai
n\extlibs\grpc\src\core\ext\transport\chttp2\transport\chttp2_transport.c","file
_line":1726,"referenced_errors":[{"created":"@1470428369.345000000","description":"End of TCP stream","file":"c:\main\extlibs\grpc\src\core\lib\iomgr\tcp_windows.c","file_line":179}]}

and the client console displays:

E0805 15:05:07.514000000  4924 chttp2_transport.c:1810] close_transport: {"created":"@1470423907.514000000","description":"End of TCP stream","file":"c:\main\extlibs\gr\src\core\lib\iomgr\tcp_windows.c","file_line":179}
message not available
421 Service not available

This clearly shows that the client and server are communicating the grpc::StatusCode::UNAVAILABLE, however I do not want the extra tcp_windows.c crap to appear.

My question is, how should I handle cases where an rpc method needs to return an error code instead of filling in the response message buffer. Do I always need to fill the response buffer details in?  Also on the client side do I need to do anything special to close the channel?

message OpSupportResponse {
    RXMessageType message_type  = 1;
    string datetime  = 20;  
}

service CAService {
   // rpc method to retrieve current OpSupportMessage
   rpc GetOpSupportMessage (google.protobuf.Empty) returns (OpSupportResponse) {}
}

grpc::Status
CADaemon::GetOpSupportMessage(
    ServerContext* context,
    const::google::protobuf::Empty* request,
    ca::OpSupportResponse* response)
{
        if (mpOpSupportMessage) {
            response->set_message_type(ca::RXMessageType::OPERATIONAL_SUPPORT);
            response->set_datetime(value);
            return grpc::Status::OK;
        } else { // still waiting for the message
            // return grpc::Status::OK;
            return grpc::Status(grpc::StatusCode::UNAVAILABLE,
                "message not available");
        }
}

John Coffey

unread,
Aug 5, 2016, 10:29:40 PM8/5/16
to grpc.io
Answering my own question.... I finally figured this out, I was on gRPC release-0_15_1, switching to v1.0.x completely removed the problem.  Hope this useful for others.

John
Reply all
Reply to author
Forward
0 new messages