Seg Fault when calling grpc::ServerInterface::RegisteredAsyncRequest::IssueRequest

57 views
Skip to first unread message

Alistair Lowe

unread,
Sep 10, 2018, 6:22:16 PM9/10/18
to grpc.io
Hi guys,

I'm trying to implement my own gRPC 1.14.2 C++ async server loosely following the hello world examples, however I receive a segfault when attempting to make an asynchronous request as per the below stack trace:

grpc::ServerInterface::RegisteredAsyncRequest::IssueRequest(void*, grpc_byte_buffer**, grpc::ServerCompletionQueue*) (Unknown Source:0)
grpc::ServerInterface::PayloadAsyncRequest<OpenIoTServer::EnrollRequest>::PayloadAsyncRequest(grpc::ServerInterface::PayloadAsyncRequest<OpenIoTServer::EnrollRequest> * const this, void * registered_method, grpc::ServerInterface * server, grpc::ServerContext * context, grpc::internal::ServerAsyncStreamingInterface * stream, grpc::CompletionQueue * call_cq, grpc::ServerCompletionQueue * notification_cq, void * tag, OpenIoTServer::EnrollRequest * request) (/usr/local/include/grpcpp/impl/codegen/server_interface.h:212)
grpc::ServerInterface::RequestAsyncCall<OpenIoTServer::EnrollRequest>(grpc::ServerInterface * const this, grpc::internal::RpcServiceMethod * method, grpc::ServerContext * context, grpc::internal::ServerAsyncStreamingInterface * stream, grpc::CompletionQueue * call_cq, grpc::ServerCompletionQueue * notification_cq, void * tag, OpenIoTServer::EnrollRequest * message) (/usr/local/include/grpcpp/impl/codegen/server_interface.h:275)
grpc::Service::RequestAsyncUnary<OpenIoTServer::EnrollRequest>(grpc::Service * const this, int index, grpc::ServerContext * context, OpenIoTServer::EnrollRequest * request, grpc::internal::ServerAsyncStreamingInterface * stream, grpc::CompletionQueue * call_cq, grpc::ServerCompletionQueue * notification_cq, void * tag) (/usr/local/include/grpcpp/impl/codegen/service_type.h:96)
OpenIoTServer::Device::WithAsyncMethod_Enroll<OpenIoTServer::Device::Service>::RequestEnroll(OpenIoTServer::Device::WithAsyncMethod_Enroll<OpenIoTServer::Device::Service> * const this, grpc::ServerContext * context, OpenIoTServer::EnrollRequest * request, grpc::ServerAsyncResponseWriter<OpenIoTServer::EnrollResponse> * response, grpc::CompletionQueue * new_call_cq, grpc::ServerCompletionQueue * notification_cq, void * tag) (/home/developer/deployment-management-controller/device.grpc.pb.h:170)
main() (/home/developer/deployment-management-controller/main.cpp:81)

I've simplified my code as much as possible and the problem is still occurring:
#include "device.grpc.pb.h"
#include <string>
#include <boost/fiber/algo/algorithm.hpp>
#include <grpcpp/grpcpp.h>
#include <boost/thread.hpp>
#include <boost/fiber/scheduler.hpp>

using grpc::ServerAsyncResponseWriter;
using grpc::ServerBuilder;
using grpc::ServerContext;
using grpc::ServerCompletionQueue;
using grpc::Status;

int main( int, char** )
{
std::unique_ptr<ServerCompletionQueue> cq_;
OpenIoTServer::Device::AsyncService service_;
std::unique_ptr<Server> server_;

ServerBuilder serverBuilder;
serverBuilder.AddListeningPort( "127.0.0.1:1000", InsecureServerCredentials() );
serverBuilder.RegisterService( &service_ );

cq_ = serverBuilder.AddCompletionQueue();
server_ = serverBuilder.BuildAndStart();
ServerContext ctx_;
EnrollRequest request_;
EnrollResponse reply_;
ServerAsyncResponseWriter<EnrollResponse> responder_(&ctx_);

service_.RequestEnroll(&ctx_, &request_, &responder_, cq_.get(), cq_.get(),(void*)1); // SEGFAULT WITHIN HERE
}

My protobuf is generated from the following using protoc version 3.5.1:
syntax = "proto3";
package OpenIoTServer;

service Device
{
rpc Enroll(EnrollRequest) returns (EnrollResponse);
}

message EnrollRequest
{
bytes device_id = 1;
bytes user_id = 2;
}

message EnrollResponse
{
bool success = 1;
}

Any suggestions would be very-much appreciated!

Many thanks

Yang Gao

unread,
Sep 10, 2018, 6:35:33 PM9/10/18
to alis...@skyiot.co.uk, grpc.io
The first thing I would check is whether server_ == nullptr after BuildAndStart.

--
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 grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
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/6cea7726-cc2b-4ea0-bdcf-1a38f6301e43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Vijay Pai

unread,
Sep 10, 2018, 6:42:51 PM9/10/18
to grpc.io
 In particular, a reason that this is likely to fail out is that your listening port is #1000 , which will only work if you are root.

Alistair Lowe

unread,
Sep 13, 2018, 3:49:04 PM9/13/18
to grpc.io
Thanks a bunch Vijay,

I had foolishly made an assumption because there wasn't error checking in the example that a valid pointer was always returned at this point. You were right about the port also and so I've learned something about the history of Linux ports < 1024, which I probably should have known by now already!...
Reply all
Reply to author
Forward
0 new messages