while using server-side stream message, client always got: code = Unknown desc = Unexpected error in RPC handling

68 views
Skip to first unread message

yonnie...@gmail.com

unread,
Sep 27, 2019, 10:54:39 PM9/27/19
to grpc.io
Hi, all
   I'm using grpc + protobuf with server side written in c++ and client side written in golang.

One grpc method i used server-side stream message, when client connect to the server side, client always got : code = Unknown desc = Unexpected error in RPC handling

The grpc connection inited successfully and other methods worked fine.

Anybody knows why this error means?
The method is the following: client will wait server-side write message to it

rpc RegisterNotification(google.protobuf.Empty) returns (stream Notification);


Easwar Swaminathan

unread,
Oct 2, 2019, 2:04:13 PM10/2/19
to grpc.io
Could you please provide relevant snippets of server and client code, for us to be able to debug this issue better.

yonnie...@gmail.com

unread,
Oct 24, 2019, 9:45:01 PM10/24/19
to grpc.io



I'm sorry that reply you late.

The service side code was written in c++:
Status RobotControllerServiceImpl::RegisterNotification(::grpc::ServerContext* context, const Empty* request, ServerWriter<Notification>* writer) {
   Notification notification;
   DLOG(INFO) << "Register notification begin , context cancelled:" << context->IsCancelled();
   while ((*run) == 1 && !context->IsCancelled()) {
 
           notification.Clear();
           Notice* notice = notification.add_items();
           
// doing write something      
     
           writer->Write(notification);
           // DLOG(INFO) << "Send notification," << " type: " << n.type << ", id: " << n.id << ", value: " << n.value << ", ret: " << ret;
       }
   }
    context->TryCancel();
   DLOG(INFO) << "Register notification end, maybe exit!";
   return Status::OK;
}

The client side code was written in golang:
func (rc *RobotController) streamRegisterNotification() error {
   ctx := context.Background()
   stream, err := (*rc.client).RegisterNotification(ctx, &empty.Empty{})
   if err != nil {
      log().Errorf("get notification stream err: %v", err)
      return err
   }

   defer func() {
stream.
CloseSend()
}()
for {

data
, err := stream.Recv()
if err == io.EOF {
log().Error("notification run io.EOF")
break
}
if err != nil {
log().Errorf("notification recv err:%v, data: %v", err.Error(), data)
return err
}
// process the notification
}

   return nil
}

The protobuf definition defines here

message Notice {
  enum NoticeType {
    NOTICE_STATE = 0;
    NOTICE_ERROR = 1;  
    NOTICE_BUTTON = 2;
  }


  enum NoticeId {
    NOTICE_ID_1 = 0;  
    NOTICE_ID_2 = 1;  
  }

  NoticeType type = 1;
  NoticeId id = 2;
  int32 value = 3;
  int32 code = 4;
  repeated double lol = 5;
}

message Notification {
 repeated Notice items = 1;
}

service RobotController {
Reply all
Reply to author
Forward
0 new messages