gRPC trigger to initiate client disconnection from server

108 views
Skip to first unread message

Ram

unread,
Aug 19, 2021, 12:53:27 AM8/19/21
to grpc.io

Hello all,

In the gRIBI protofile specification there is a requirement to close the client connection based on some invalid request parameters, it looks like that needs to be initiated by the network element(server).

// If the client redundancy mode is ALL_PRIMARY, but a client 
// sends election_id, the network element closes the connection 
// to the client and responds with FAILED_PRECONDITION in 
// status.proto's `code` and sets ModifyRPCErrorDetails.reason 
// to ELECTION_ID_IN_ALL_PRIMARY

Is there a mechanism available in gRPC C++ to achieve this? Is it possible to get the client connection info from RPC context and initiate disconnection upon invalid parameters?

Thank you, -Ram.

Piotr Morgwai Kotarbinski

unread,
Aug 19, 2021, 3:29:16 AM8/19/21
to grpc.io
Hi,
I'm assuming that you mean "...requirement for the server to close the connection from the client based on...".
I strongly believe that by "closes the connection to the client" the author did not mean the whole HTTP/2 connection but only the given HTTP/2 stream on which the client made such a request. If my guess is correct, then all you need to do on your server is to send error response with the status set to FAILED_PRECONDITION in the trailing meta-data. I don't know C++ API, but in Java it's as simple as responseObserver.onError(Status.FAILED_PRECONDITION.asException()) and I guess in C++ there is a similar corresponding error sending mechanism as well.

Hope this helps :)

Ram

unread,
Aug 20, 2021, 10:56:51 AM8/20/21
to grpc.io
Thank you for the response. Checked with authors of proto, it does look like they meant the stream to be closed not the connection.
Reply all
Reply to author
Forward
0 new messages