c++ early client side termination of SERVER_STREAMING RPC

36 views
Skip to first unread message

osscon...@gmail.com

unread,
Apr 28, 2020, 8:20:30 AM4/28/20
to grpc.io

Hi,


I am writing a C++ future/promised based interface around the grpc c++ API. Some important details around termination of the streams are not clear to me, even after reading through discussions here and many open/closed issues in the GitHub repository.


Suppose a client calls a SERVER_STREAMING RPC using ClientAsyncReader, ClientContext etc. 


Finish()

Can only be called after cq.Next() returns ok = false for a Read() operation. So the normal sequence could look like:


  • Read(), ok =true
  • Read(), ok =true
  • Read(), ok =true
  • Read(), ok = true
  • Read(), ok = false // nothing more to read
  • Finish(), ok = true // gets RPC status
  • Delete ClientAsyncReader and ClientContext


Now suppose the client throws an exception while processing the response returned by the second Read(). From what I understand I have to call ClientContext::TryCancel() and then keep calling Read() until ok = false, then call Finish():


  • Read(), ok =true
  • Read(), ok =true, exception while applying business logic
  • ClientContext::TryCancel()
  • Read(), ok =true // could happen from what I understand
  • Read(),  false = true
  • Finish(), ok = true
  • Delete ClientAsyncReader and ClientContext

I have a strong feeling it's required to *always* call Finish() before releasing resources, but I have not found any doc/issue/discussion, which confirms it 100%. Is there any other alternative way to terminate the stream in an orderly fashion?


Patrick

osscon...@gmail.com

unread,
Apr 28, 2020, 11:51:39 AM4/28/20
to grpc.io
Assuming I have no uncompleted async operation (like Read()), is it then valid to skip the Read()-Finish() sequence and immediately release the resources?
    • Read(), ok =true
    • Read(), ok =true, exception while applying business logic
    • ClientContext::TryCancel()
    • Delete ClientAsyncReader and ClientContext
    Patrick
    Reply all
    Reply to author
    Forward
    0 new messages