C++ - Unable to catch client disconnection with `IsCancalled()`

17 views
Skip to first unread message

Venelin Vasilev

unread,
Oct 16, 2020, 9:29:17 AM10/16/20
to grpc.io
I am using sync api with C++.

Here is how on server side I am checking if the client has stopped the stream.

grpc::Status AuthServer::ConnectServiceImpl::HearthBeat(grpc::ServerContext *context,
grpc::ServerReaderWriter<Pulse, Pulse> *stream) {
Pulse note;
if(ctx_.IsCancelled()){
std::cout << "DISCONNECT" << std::endl;
    }
while (stream->Read(&note)) {
Pulse reply;
reply.set_rate(note.rate()+1);
std::cout << "RECEIVED: " << note.rate() << std::endl;
stream->Write(reply);
}

return grpc::Status::OK;
}

This is bidi stream which is stopped forcefully on client side with killing the client app and still the "DISCONNECT" message does not appear.

Why is that, am I using `IsCancelled()` not correctly?
Reply all
Reply to author
Forward
0 new messages