[C++] Get grpc::status of async bi-directional stream that was closed by server

305 views
Skip to first unread message

edelma...@gmail.com

unread,
Sep 28, 2017, 8:23:13 PM9/28/17
to grpc.io
We have an async bi-directional streaming setup. We have implemented a health check on the stream and have logic where the server decides a client is stale or gone and closes the connection with that client.

We have a Go server that is setting the error like so (I hope this is enough to give you an idea, I don't know the Go side at all...):
    done <- errors.New(fmt.Sprintf("Server did not receive pong within grace period; subscription terminated"))

With a Python client, we get an exception on the stream correctly:
    _Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNKNOWN, Server did not receive pong within grace period; subscription terminated)>

However, in C++ I cannot seem to get the above error output, which would help the client decide how to proceed.

What I have is a completion queue on which I call AsyncNext(). I can successfully get the 'ok' parameter to return false once the above termination happens. Reading through the docs and other posts here on groups it looks as though I then need to call Finish on my ReaderWriter object and that has an out param for a status. When I call that, it seems the status is never set and I also never see the tag I set for the Finish operation come through my completion queue. I have tried cancelling the stream from the client when this happens and that sets the status, but only to say that it was cancelled.

A couple reasons I need the status code and status message: I want to be able to respond to different issues in different and appropriate ways. I read that AsyncNext setting 'ok' to false does not always mean there is an issue.

Can someone help me connect these dots into the proper way to get the error messages from the server in this situation?

Thanks!
Eric Edelman

Sree Kuchibhotla

unread,
Oct 10, 2017, 7:14:54 PM10/10/17
to grpc.io

Sree Kuchibhotla

unread,
Oct 10, 2017, 7:18:28 PM10/10/17
to grpc.io
Hi Eric,
Can you paste snippets of your code on server side and the client side ?

I am imagining you are doing something like the following:
on server:    
  server_stream->Finish(<the status you want to send>..)
  cq->AsyncNext();   

on client:
  client_stream->Read(..)
  cq->AsyncNext()  // Would have returned your tag and ok=false - saying that read failed

  client_stream->Finish(..)
  cq->AsyncNext() // would have returned your tag..ok=false and the status from server.

thanks,
-Sree
Reply all
Reply to author
Forward
0 new messages