I’ve tried all 3 methods of async gRPC calls and they all give a seg fault. When trying the callback example here I get a seg fault when calling the RPC. When trying the AsyncX method here I get a seg fault at cq_.Next
once call->response_reader->Finish
has been called. If I use PrepareAsyncX, StartCall it’s the same thing. Is there something missing in these examples?
My code looks like:
proto:
service FooService
{
rpc Foo(FooRequest) returns (FooResponse);
}
AsyncX method
ServerBuilder builder_;
std::unique_ptr<ServerComplestionQueue> cq = builder_.AddCompletionQueue();
ServerComplestionQueue *cq_ = cq.get();
//...
ClientContext cc;
FooRequest req;
TagWrapper* tag = new TagWrapper;
tag->reader = stub_.AsyncFoo(&cc, req, cq_);
tag->reader->Finish(&tag->resp_, &tag->status_, (void*)tag);
//In another thread
void* tag = NULL;
bool ok = false;
cq_->Next(&tag, &ok);
cq_.Next
is called in its own thread before Finish
and once call->response_reader->Finish
is called, the call to cq_.Next
seg faults. PrepareAsyncFoo
is the same, it just has a call to call->response_reader->StartCall()
before Finish
.
Callback method, which would be preferable since it’s far more straight forward:
ClientContext cc;
FooRequest req;
FooResponse resp;
stub_->async()->Foo(&cc, &req, &resp, [](grpc::Status status) { printf("%dn", status.ok()); });
Here the call to stub_->async()->Foo seg faults.