0

Here is my protobuf file:

service gRPCComServeFunc {
  rpc sendFile(FileRequest) returns (google.protobuf.Empty) {}
}

My questions:

  • Q1: I wonder does the receiver need to return an google.protobuf.Empty object to the sender or not (which means the receiver doesn't need to return anything)
  • Q2: In other words, I wonder when the remote rpc is ended in the sender? The moment when the sender get feedback (e.g. an Empty object) or when the the function sendFile ends in the receiver, especially when the return type is google.protobuf.Empty?
  • Q3: If the function sendFile in the receiver will run for a long time and the receiver doesn't return Empty object, will the sender report timeout or socket closed error?
david
  • 842
  • 2
  • 8
  • 25

1 Answers1

1

google.protobuf.Empty has no impact to RPC behavior. The receiver will need to return a google.protobuf.Empty, which is empty but is still a message and would be distinct from "no returned message." The RPC when end when the service completes the operation. It is really similar in many ways to a void return in Java; nothing special happens, other than the return is not present.

Returning google.protobuf.Empty is common for operations like delete, which the client is expecting to have completed when the call returns. The same is true for the sendFile example, as another RPC could depend on the file creation having completed successfully. The return type really has no impact of whether the RPC needs to wait for the operation to complete and whether the operation could fail.

So if sendFile is slow it could be failed by the deadline being exceeded, if the client sets one. And if the TCP connection dies it could fail with a socket error. The service implementation of sendFile is free to return early before the operation is fully complete, but that is then part of the service contract and semantics. Returning early is common for large operations that may take hours, generally with companion methods to check the operation's progress.

Eric Anderson
  • 24,057
  • 5
  • 55
  • 76