Sorry for the late response.
There is no special method to 'close' the BiDi streams. On the server, just
returning a status would mean that you are done with the stream.
However, in the example you have given, you seem to be calling just 1 read.
Since you mentioned you are noticing a memory leak, I was wondering...are
you sure that you are reading all the messages that client is sending ?
You don't have to really check 'context->IsCancelled()' here.
stream->Read() has a return value. It returns 'true' as long as there is a
message to read from the client. stream->Read() returns a 'false' either
when the client gracefully finished the writes (by calling
stream->WritesDone() and stream->Finish() on the client side) or if the
client cancelled the RPC or there was some other error..
So I recommend you rewrite your loop as
Status BidiServiceImpl::BiDiStreamingRpc(...)
{
..
while (stream->Read(&req)) {
getRest(resp);
stream->Write(resp);
}
// You can check context->IsCancelled() here if you
// are interested in whether the RPC was cancelled
return Status(..)
}
thanks,
Sree
On Monday, May 1, 2017 at 10:45:37 PM UTC-7, [email protected] wrote:
>
>
> Hello,
>
> Is there a way to close down BiDi streaming gracefully from C++ server
> thread (pthr) when c++ client gets aborted? When I simply return from Bidi
> streaming rpc based on IsCancelled() I observe memory leaks.
>
> Here is the sample code
>
>
> Status BiDiServiceImpl::BiDiStreamingRpc(::grpc::ServerContext* context,
> ::grpc::ServerReaderWriter< BiDiResponse, BiDiRequest>* stream)
> {
> BiDiRequest req;
> BiDiResponse resp;
>
> stream->Read(&req);
> while(context->IsCancelled() == false)
> {
> getResp(resp);
> stream->Write(resp);
> }
> return(Status(Status::GRPC_OK, ""));
> }
>
>
> Thanks
> Rajeev
>
>
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/143079af-c284-49ab-9626-a4545adab9a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.