title: gRPC keeps returning error code 12 from server
body: <p>I need to implement a distributed database and I implemented based on gRPC example. The following is my code snippet.
  <code>sundial_sync_server.h</code></p>
  <pre><code>#ifndef SUNDIAL_GRPC_SYNC_SERVER_H
  #define SUNDIAL_GRPC_SYNC_SERVER_H
  
  #endif //SUNDIAL_GRPC_SYNC_SERVER_H
  
  #include &quot;sundial_grpc.grpc.pb.h&quot;
  #include &quot;sundial_grpc.pb.h&quot;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;string&gt;
  #include &lt;grpcpp/grpcpp.h&gt;
  using grpc::Channel;
  using grpc::ServerContext;
  using grpc::Status;
  using sundial_rpc::SundialRequest;
  using sundial_rpc::SundialResponse;
  using sundial_rpc::Sundial_GRPC_SYNC;
  #ifndef ABC
  #define ABC
  class SundialServiceImp final : public Sundial_GRPC_SYNC::Service
  {
      public:
      Status contactRemote(::grpc::ServerContext* context, const ::sundial_rpc::SundialRequest* request, ::sundial_rpc::SundialResponse* response) override;
      void run();
  
  };
  #endif
  </code></pre>
  <p><code>sundial_sync_server.cpp</code></p>
  <pre><code>#include &quot;sundial_grpc.grpc.pb.h&quot;
  #include &quot;sundial_grpc.pb.h&quot;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;string&gt;
  #include &lt;grpcpp/grpcpp.h&gt;
  #include &quot;txn.h&quot;
  #include &quot;global.h&quot;
  #include &quot;manager.h&quot;
  #include &quot;stats.h&quot;
  #include &quot;helper.h&quot;
  #include &quot;grpc_sync_server.h&quot;
  #include &quot;txn_table.h&quot;
  #include &lt;grpcpp/grpcpp.h&gt;
  #include &lt;grpcpp/health_check_service_interface.h&gt;
  #include &lt;grpcpp/ext/proto_server_reflection_plugin.h&gt;
  using grpc::ServerContext;
  using grpc::Status;
  using sundial_rpc::SundialRequest;
  using sundial_rpc::SundialResponse;
  using sundial_rpc::Sundial_GRPC_SYNC;
  using grpc::Server;
  using grpc::ServerBuilder;
  Status SundialServiceImp::contactRemote(::grpc::ServerContext* context, const ::sundial_rpc::SundialRequest* request, ::sundial_rpc::SundialResponse* response){
       if (request-&gt;request_type() == SundialRequest::SYS_REQ) {
          glob_manager-&gt;receive_sync_request(); 
          response-&gt;set_response_type( SundialResponse::SYS_RESP );
          return Status::OK;
      }
      uint64_t txn_id = request-&gt;txn_id();
      TxnManager * txn_man = txn_table-&gt;get_txn(txn_id);
      // If no TxnManager exists for the requesting transaction, create one.
      if (txn_man == NULL) {
          //printf(&quot;adding txnID=%ld into txn_table\n&quot;, txn_id);
          assert( request-&gt;request_type() == SundialRequest::READ_REQ );
          txn_man = new TxnManager();
          txn_man-&gt;set_txn_id( txn_id );
          txn_table-&gt;add_txn( txn_man );
      }
      // the transaction handles the RPC call
      txn_man-&gt;process_remote_request(request, response);
      // if the sub-transaction is no longer required, remove from txn_table
      if (response-&gt;response_type() == SundialResponse::RESP_ABORT
          || response-&gt;response_type() == SundialResponse::PREPARED_OK_RO
          || response-&gt;response_type() == SundialResponse::PREPARED_ABORT
          || response-&gt;response_type() == SundialResponse::ACK) {
          txn_table-&gt;remove_txn( txn_man );
          delete txn_man;
      }
      return Status::OK;
  }
  
  void SundialServiceImp::run(){
      std::istringstream in(ifconfig_string);
      string line;
      uint32_t num_nodes = 0;    
      string port;
      while (getline (in, line)) {
          if (line[0] == '#')
              continue;
          else {
              if (num_nodes == g_node_id) {
                  port = line.substr(0, line.length());
                  break;
              }
              num_nodes ++;
          }
      }
      port.append(sync_port);
      grpc::EnableDefaultHealthCheckService(true);
      grpc::reflection::InitProtoReflectionServerBuilderPlugin();
      ServerBuilder builder;
      builder.AddListeningPort(port, grpc::InsecureServerCredentials());   
      builder.RegisterService(this);   
      std::unique_ptr&lt;Server&gt; server(builder.BuildAndStart());
      std::cout &lt;&lt; &quot;Server listening on &quot; &lt;&lt; port &lt;&lt; std::endl;
      server-&gt;Wait();
  }
  </code></pre>
  <p>`sundial_sync_client.h'</p>
  <pre><code>#endif //SUNDIAL_GRPC_CLIENT_H
  #include &quot;sundial_grpc.grpc.pb.h&quot;
  #include &quot;sundial_grpc.pb.h&quot;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;string&gt;
  #include &lt;grpcpp/grpcpp.h&gt;
  using grpc::Channel;
  using grpc::ClientContext;
  using grpc::Status;
  using sundial_rpc::SundialRequest;
  using sundial_rpc::SundialResponse;
  using sundial_rpc::Sundial_GRPC_SYNC;
  //toDo: now assume we only have 2 nodes
  #ifndef SSC
  #define SSC
  class Sundial_Sync_Client{
  public:
      Sundial_Sync_Client(std::shared_ptr&lt;Channel&gt;* channel);
      Status contactRemote(uint64_t node_id,SundialRequest&amp; request, SundialResponse* response);
  private:
      std::unique_ptr&lt;Sundial_GRPC_SYNC::Stub&gt; stub_;
  };
  #endif
  </code></pre>
  <p><code>sundial_sync_client.cpp</code></p>
  <pre><code>#include &quot;sundial_grpc.grpc.pb.h&quot;
  #include &quot;sundial_grpc.pb.h&quot;
  #include &quot;grpc_sync_client.h&quot;
  #include &lt;iostream&gt;
  #include &lt;memory&gt;
  #include &lt;string&gt;
  #include &lt;grpcpp/grpcpp.h&gt;
  #include &quot;txn.h&quot;
  #include &quot;global.h&quot;
  #include &quot;helper.h&quot;
  #include &quot;manager.h&quot;
  #include &quot;stats.h&quot;
  using grpc::Channel;
  using grpc::ClientContext;
  using grpc::Status;
  using sundial_rpc::SundialRequest;
  using sundial_rpc::SundialResponse;
  using sundial_rpc::Sundial_GRPC_SYNC;
  //toDo: add more nodes to it
  Sundial_Sync_Client::Sundial_Sync_Client(std::shared_ptr&lt;Channel&gt;* channel){
      for(int i=0; i&lt;g_num_nodes;i++){
          if(i==g_node_id)
              continue;
      //stub_[i]=Sundial_GRPC_SYNC::NewStub(channel[i]);
      stub_=Sundial_GRPC_SYNC::NewStub(channel[i]);
      }
      
  }
  
  Status
  Sundial_Sync_Client::contactRemote(uint64_t node_id, SundialRequest&amp; request, SundialResponse* response){
      //toDo: choose the right stub with node id
      ClientContext context;
      printf(&quot;Client sends request\n&quot;);
      //Status status = stub_[node_id]-&gt;contactRemote(&amp;context, request, &amp;response);
      Status status = stub_-&gt;contactRemote(&amp;context, request, response);
      if (status.ok()) {
          //printf(&quot;status ok\n&quot;);
          glob_stats-&gt;_stats[GET_THD_ID]-&gt;_resp_msg_count[ response-&gt;response_type() ] ++;
          glob_stats-&gt;_stats[GET_THD_ID]-&gt;_resp_msg_size[ response-&gt;response_type() ] += response-&gt;SpaceUsedLong();
          return status;
      } else {
          std::cout &lt;&lt; status.error_code() &lt;&lt; &quot;: &quot; &lt;&lt; status.error_message()
                    &lt;&lt; std::endl;
          return status;
      }
  
  }
  </code></pre>
  <p>It runs pretty smoothly at the setup. I did get the ip address and let servers run at the right address. However, when I make the client send request, the status it returns always has error code 12 without error message.</p>